Monday, June 15, 2009

Microsoft. Net - Replace BitMap Color

Private Function ReplaceBitMapColor(ByVal originalBMP As Bitmap, _
ByVal oldColor As Color, _
ByVal newColor As Color) As Bitmap
Dim image As New Bitmap(originalBMP)
Dim graphics As Graphics = Graphics.FromImage(image)
Dim map As ColorMap() = New ColorMap() {New ColorMap}
map(0).OldColor = oldColor
map(0).NewColor = newColor

Dim imageAttr As New ImageAttributes
imageAttr.SetRemapTable(map)

Dim destRect As New Rectangle(0, 0, image.Width, image.Height)
graphics.DrawImage(image, destRect, 0, 0, _
image.Width, image.Height, _
GraphicsUnit.Pixel, imageAttr)

Return image

End Function

No comments:

Post a Comment