Change the color of part of an image

D

Dave Wurtz

All,

I have an image (bitmap) that I want to change all of the blue pixels
to red, for example. Is this possible to do?

Thanks in advance!
Dave Wurtz
 
D

Dave Wurtz

Mick,

Thanks for replying, but I don't quite understand the ImageAttribute.
Do you have an example?

Dave
 
D

Dave Wurtz

I have a solution based on Mick's suggestion and performing some more
searches. Here's the function if anyone else is looking for the same
thing:

Public Function ChangeImageColor(ByVal image As
System.Drawing.Image, ByVal oldColor As System.Drawing.Color, ByVal
newColor As System.Drawing.Color) As System.Drawing.Image

Dim newImage As System.Drawing.Image = DirectCast(image.Clone,
System.Drawing.Image)
Dim g1 As System.Drawing.Graphics =
System.Drawing.Graphics.FromImage(newImage)

' Create a color map.

Dim colorMap(0) As System.Drawing.Imaging.ColorMap
colorMap(0) = New System.Drawing.imaging.ColorMap
colorMap(0).OldColor = oldColor
colorMap(0).NewColor = newColor

' Create an ImageAttributes object, and then pass the
transformerobject to the SetRemapTable method.
Dim imageAttr As System.Drawing.Imaging.ImageAttributes = New
System.Drawing.Imaging.ImageAttributes
imageAttr.SetRemapTable(colorMap)

g1.DrawImage(newImage, New System.Drawing.Rectangle(0, 0,
newImage.Width, newImage.Height), 0, 0, newImage.Width,
newImage.Height, Drawing.GraphicsUnit.Pixel, imageAttr)

Return newImage

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top