2

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.

Steve T
  • 7,729
  • 6
  • 45
  • 65

2 Answers2

6

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.

Joseph
  • 383
  • 2
  • 7
-1

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.

shiladitya
  • 2,290
  • 1
  • 23
  • 36