I am trying to draw some basic graphics primitives(line, rectangle etc.) using GDI+ apis on 4-bit indexed bitmaps. I am using Bitmap() functions for creating the bitmap and loading the bitmaps.
Bitmap myBitmap(100/*width*/,100/*height*/,PixelFormat4bppIndexed/*Pixel format*/);
Graphics graphics(&myBitmap);
SolidBrush brush(Color(255,128,0,0));
graphics.FillRectangle(&brush,0,0,100,100);
But this doesn’t work(No Rectangle created).
What could be the problem? I tried manually using LockBits and modifying the bits manually, it works well, then why it doesn’t work with Graphics gdi+ operations.
Finally I managed to solve my problem. To perform gdi+ operations using Graphics object on 4 bit indexed bitmap, we need to perform following steps.
Though I didnt try with 8bpp but I think similar operations can be performed on 8bpp also.
Hope this help others also.