Sepia
This algorithm converts specified image to old brown photo.
Public Shared Sub ApplySepia(ByRef bmp As Bitmap, depth As Integer)
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 Pixel As Integer = 0
While CInt(ptr) <> stopAddress
Marshal.WriteByte(ptr, CByte(Math.Truncate((0.299 * Marshal.ReadByte(ptr + 2)) + (Marshal.ReadByte(ptr + 1) * 0.587) + (Marshal.ReadByte(ptr) * 0.114))))
Pixel = Marshal.ReadByte(ptr + 2) + (depth * 2)
If Pixel > 255 Then
Pixel = 255
End If
Marshal.WriteByte(ptr + 2, CByte(Pixel))
Pixel = Marshal.ReadByte(ptr + 1) + depth
If Pixel > 255 Then
Pixel = 255
End If
Marshal.WriteByte(ptr + 1, CByte(Pixel))
ptr += 3
End While
bmp.UnlockBits(bmpData)
End Sub
Example
DIm b As Bitmap = CType(Image.FromFile("rose.jpg"), Bitmap)
ApplySepia(b, 50)