PC Review


Reply
Thread Tools Rate Thread

Change the color of part of an image

 
 
Dave Wurtz
Guest
Posts: n/a
 
      11th Aug 2005
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

 
Reply With Quote
 
 
 
 
Mick Doherty
Guest
Posts: n/a
 
      11th Aug 2005
Draw the image using ImageAttributes with SetRemapTable.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


"Dave Wurtz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Dave Wurtz
Guest
Posts: n/a
 
      11th Aug 2005
Mick,

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

Dave

 
Reply With Quote
 
Dave Wurtz
Guest
Posts: n/a
 
      12th Aug 2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change cell background color as part of the If statement? Jim H Microsoft Excel Worksheet Functions 2 23rd Sep 2009 11:58 PM
Change font color as part of if/then tina Microsoft Excel Misc 17 1st Feb 2008 12:32 AM
change color of a cel 2 part questionl... Dr,Bob Microsoft Excel Discussion 1 23rd Dec 2004 03:18 AM
Change font/color of part of the text in a cell in windows datagrid Garima Sajwan Microsoft Dot NET Framework Forms 0 30th Jun 2004 11:04 AM
Excel VBA: Dropdown Box and Image Color Change mwh5604 Microsoft Excel Misc 0 12th Jan 2004 01:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:41 PM.