Color

This algorithm adds/subtracts a value to each color.

   



									Public Shared Sub ApplyColor(ByRef bmp As Bitmap, c As System.Drawing.Color)
	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

	Dim RetVal As Integer

	While CInt(ptr) <> stopAddress
		RetVal = Marshal.ReadByte(ptr + 2) + CInt(c.R)
		If RetVal < 0 Then
			RetVal = 0
		ElseIf RetVal > 255 Then
			RetVal = 255
		End If
		Marshal.WriteByte(ptr + 2, CByte(RetVal))

		RetVal = Marshal.ReadByte(ptr + 1) + CInt(c.G)
		If RetVal < 0 Then
			RetVal = 0
		ElseIf RetVal > 255 Then
			RetVal = 255
		End If
		Marshal.WriteByte(ptr + 1, CByte(RetVal))

		RetVal = Marshal.ReadByte(ptr) + CInt(c.B)
		If RetVal < 0 Then
			RetVal = 0
		ElseIf RetVal > 255 Then
			RetVal = 255
		End If
		Marshal.WriteByte(ptr, CByte(RetVal))

		ptr += 3
	End While

	bmp.UnlockBits(bmpData)
End Sub
								


Example

									DIm b As Bitmap = CType(Image.FromFile("rose.jpg"), Bitmap)
ApplyColor(b, Color.Red)