What is the best way to set the RGB components of every pixel in a System.Drawing.Bitmap
to a single, solid color? If possible, I'd like to avoid manually looping through each pixel to do this.
Note: I want to keep the same alpha component from the original bitmap. I only want to change the RGB values.
I looked into using a ColorMatrix
or ColorMap
, but I couldn't find any way to set all pixels to a specific given color with either approach.
Yes, use a ColorMatrix. It ought to look like this:
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 1 0
R G B 0 1
Where R, G and B are the scaled color values of the replacement color (divide by 255.0f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With