I\'m using WinForms. I have a picture-box in my form. When I open a picture in the picture-box I am able to invert the colors back and forth on a click of a button, but my c
In case someone need the similar code in VB.NET.
Also note the variable inv.A instead of the value 255. In case your picturebox has transparency you need this.
Public Function InvertImageColors(ByVal p As Image) As Image
Dim pic As New Bitmap(p)
For y As Integer = 0 To pic.Height - 1
For x As Integer = 0 To pic.Width - 1
Dim inv As Color = pic.GetPixel(x, y)
inv = Color.FromArgb(inv.A, 255 - inv.R, 255 - inv.G, 255 - inv.B)
pic.SetPixel(x, y, inv)
Next x
Next y
Return pic
End Function
Usage:
pic.image = InvertImageColors(pic.image)