473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Change the color of part of an image

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

Nov 21 '05 #1
3 5125
Draw the image using ImageAttributes with SetRemapTable.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Dave Wurtz" <da********@asdsoftware.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Nov 21 '05 #2
Mick,

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

Dave

Nov 21 '05 #3
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

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ron | last post by:
Hi, I have a page where i would like like to change the background image depending on the 'Request.Params' received value in the code behind. There are three different image that can be loaded....
7
by: jzieba | last post by:
I found the following script that changes the text based on a user selection. I want to modify the code to change an image source based on the user selection. I have been told I can do this with...
1
by: difah | last post by:
Hello, I'am currently designing a reportviewer, and what i want to do is when the user click on a image, this image change. I know how to change dynamically the image on load but not on click. ...
1
by: anmcafresher | last post by:
Hi Guys, I am working with an option where I do want to print a background image without enabling the "Print Background Color and Image" in the IE. I do want to get this image printed on each...
1
by: Anuhas | last post by:
Dear experts, I need to change the background image of a windows form at an event of a mouse click. Please give me the relavent method and codes. ...
2
by: Jim | last post by:
How can I use JavaScript to change a background image in a table cell? Here's the code for the cell <td width="338" valign="top" background="../images/ LEC_Q1.jpg"><div...
9
by: ghjk | last post by:
change the background image when Button Click ====================================== I' developing site with php and postgres. It has menus list in the left side. and all are images(jpg) EX:Add...
1
oranoos3000
by: oranoos3000 | last post by:
hi i'd like to page for insert user's post the same page for insert new post in this site that user can bold or italic or even change color part of typed text and or add small pictures for...
1
by: Man4ish | last post by:
How mouseover can be used to change the color of image..........
1
by: Swapnil Suryawanshi | last post by:
how to change the background image at run time?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.