Invert

This algorithm inverts the colors of input image.

   



									Public Shared Sub ApplyInvert(ByRef bmp As Bitmap)
	Dim bmpData As BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb)
	Dim ptr As IntPtr = bmpData.Scan0
	Dim stopAddress As Integer = CInt(ptr) + bmpData.Stride * bmpData.Height

	While CInt(ptr) <> stopAddress
		Marshal.WriteByte(ptr, 255 - Marshal.ReadByte(ptr))
		Marshal.WriteByte(ptr + 1, 255 - Marshal.ReadByte(ptr + 1))
		Marshal.WriteByte(ptr + 2, 255 - Marshal.ReadByte(ptr + 2))

		ptr += 3
	End While

	bmp.UnlockBits(bmpData)
End Sub
								


Example

									DIm b As Bitmap = CType(Image.FromFile("rose.jpg"), Bitmap)
ApplyInvert(b)