Search code examples
c#imagegraphicspalette

DrawImage from one indexed Bitmap onto another C# .NET Framework 2.0


I have two indexed (8-bits) Bitamp, both using the same Palette in C# (.NET Framework 2.0). I want to bit block copy pixels from one onto another on designated coordinates. I had tried to use Graphics class, but get exception that it doesn't work with indexed colors, I tried also with getpixel()/setpixel() but get the same exception. It doesn't need to be quick it just have to work. And I CAN'T convert to non-indexed image and vice-versa - palette is very important for me and I can't loose any information about it.


Solution

  • GDI+ supports indexed formats very poorly. Things got better with Vista which included an update to gdiplus.dll to version 1.10. Nothing you should could on I imagine. You could hack Bitmap.Lock(), dealing with the single byte-per-pixel format is doable. But get these images into a 24 or 32bpp format I'd say.