GDI drawing onto a 4-bit bitmap
-
Greetings folks! I created a DIB section with 4 bits per pixel, so 16 colors. I selected this DIB into a DC and am trying to draw into it using FillSolidRect and Ellipse, but all i get are zeroes in the pixel data. I specified the palette entries when creating the DIB, i also tried creating a CPalette from the DIB's palette and selecting it for the DC before drawing but no matter what i do i get nothing but zeroes. All the drawing code succeeds, so there's no visible indication of failure. What might i be doing wrong here? Here's some stripped down code:
unsigned char BIHeadMem[sizeof(BITMAPINFO) + 16 * sizeof(RGBQUAD)] = {0};
BITMAPINFO &BIHead = *(BITMAPINFO *)BIHeadMem;BIHead.bmiHeader.biSize = sizeof(BIHead.bmiHeader);
BIHead.bmiHeader.biBitCount = 4;
BIHead.bmiHeader.biClrImportant = 0;
BIHead.bmiHeader.biClrUsed = 0;
BIHead.bmiHeader.biCompression = BI_RGB;
BIHead.bmiHeader.biSizeImage = 0;
BIHead.bmiHeader.biXPelsPerMeter = 0;
BIHead.bmiHeader.biYPelsPerMeter = 0;
BIHead.bmiHeader.biWidth = 32;
BIHead.bmiHeader.biHeight = -32;
BIHead.bmiHeader.biPlanes = 1;for (int I = 0; I < 16; I++)
{
BIHead.bmiColors[I].rgbRed = BIHead.bmiColors[I].rgbBlue = BIHead.bmiColors[I].rgbGreen = (BYTE)I;
BIHead.bmiColors[I].rgbReserved = 0;
}void *DummyPixels;
CBitmap bmp;
bmp.Attach(CreateDIBSection(NULL, &BIHead, DIB_RGB_COLORS, &DummyPixels, NULL, 0)); //The creation succeeds...CDC memDC;
memDC.CreateCompatibleDC(NULL); //Creation succeeds...
memDC.SelectObject(&bmp); //SelectObject succeeds...//Here i also tried creating a LOGPALETTE from the DIB's pal, making a CPalette from that and select it for memDC
//with CDC::SelectPalette (and CDC::RealizePalette) but this seems to make no difference whatsoevermemDC.FillSolidRect(0, 0, fSizeCache.WellSize, fSizeCache.WellSize, RGB(0, 0, 0)); //Success
CPen pen;
CBrush brush(RGB(2, 2, 2));pen.CreatePen(PS_SOLID, 1, RGB(1, 1, 1));
memDC.SelectObject(&brush);
memDC.SelectObject(&pen);
memDC.Ellipse(0, 0, 32, 32); //Success...When i check the memory pointed at by
DummyPixels
, it's all zeroes, if i write to this memory "manually" the palette indexes from 0 to 15 i get what i expect when blitting the DIB to antoher DC, so the DIB itself should be ok. I guess the problem here is something completely obvious and i am just not aware of it. Thanks in advance for any help.