问题
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!
回答1:
Take a look at ImageAttributes.SetRemapTable
Another example.
回答2:
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
回答3:
Use bitmap, BitBlt functionality. I show an example in here.
来源:https://stackoverflow.com/questions/11192594/c-sharp-alternative-to-setpixel