I’m trying to convert a Bitmap to an Icon and need to set the Bitmap’s palette (See GetHicon from a 16 COLOR bitmap returns an image with less colors ) . For that, I’m trying to follow this answer: but I see that the palette is empty, and I can’t create a new array because I have to change the original one. (I even tried it anyway. It doesn’t work.)
I have:
ColorPalette palette = bitmap.Palette;
Color[] entries = palette.Entries;
But entries‘s length is Zero.
So how do I change the ColorPalette?
As stated, a bitmap file won’t necessarily have a palette. Indeed, modern color files with more than 256 colors are unlikely to (but still can (I think)) use a palette. Instead, the color information comes from the pixel values themselves (rather than pointing to a palette table)
I found the following code from ( http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/4a10d440-707f-48d7-865b-1d8804faf649/). I’ve not tested it (although the author states “tested in VS 2008 c# with .net 3.5”).
It seems to handle the shrinking down the number of colors automatically…