How to convert an Indexed pixel format image to a 32-bit image?
-
21-08-2019 - |
Question
I have an image that I get and attempt to load into a graphics object using Graphics.FromImage(image), however this throws an exception if the image has an indexed pixel format.
Is there a way to safely convert an indexed image?
Update: Thanks to Joe for the tip to just draw the old image over the new one, instead I was trying to convert it. This makes a lot of sense.
Solution
One easy way is to create a new image of the same size (with a 32-bit pixel format). Then create a graphics object for that image and draw the original on top of it.
OTHER TIPS
what you can do is based on the indexes u can calculate the euclidian distance in the 3 channel color space. Then find the closest color and use those values for your new image.