Question

I have read through several articles which are alternatives to using setpixel/getpixel but I am not seeing how they relate to my issue.

I have a multicoloured image which (depending on dynamic values taken from DB) changes the color of each pixel color group to a new color.

Lets say I want all pixels with Argb value of -989556 changed to -16 & all pixels with Argb value of -1331 changed to -5383962. I am currently looking at every pixel in the Bitmap and checking their value, if they match then they are changed using setpixel.

I am sure there must be a better way but I am being too dim to see it!

Was it helpful?

Solution

Take a look at ImageAttributes.SetRemapTable

Another example.

OTHER TIPS

If you are changing entire colors then you probably do not want to change them on a per pixel basis. There is a color transformation matrix that should allow you to change all pixles of a color in an image in a few lines of code, without having to loop through and manipulate each pixel of an image, which is horrendously slow.

See these links:

http://msdn.microsoft.com/en-us/library/6tf7sa87(v=vs.71).aspx

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.colormatrix.aspx

Use bitmap, BitBlt functionality. I show an example in here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top