I have the following that creates a blank bitmap.
struct BITMAP_INFO{
BITMAPFILEHEADER bmHead;
RGBQUAD bmColor[16];
};
BITMAP_INFO bfo;
HBITMAP hbitmap;
RGBQUAD palet[16];
BYTE cdata[] = {0xff, 0xff, 0xff, //...
// Palette data
int num = 16;
BYTE * pdata = &cdata[0];
int datasz = 3*num;
int count = 0;
RGBQUAD palette[16];
ZeroMemory(bfo.bmColor, sizeof(palette));
while(count < datasz/num ){
bfo.bmColor[count].rgbRed = *pdata++;
bfo.bmColor[count].rgbBlue = *pdata++;
bfo.bmColor[count].rgbGreen = *pdata++;
bfo.bmColor[count].rgbReserved = 0;
count++;
}
BYTE data[] = {0xff,0xff,0x80,0x01,1,1,1,1,1,1,1,1,1,1,1,1, //...
//Bit data for the bitmap
PBYTE BitmapImage = (BYTE*)LockResource;
BITMAPINFO * BitmapInfo = (BITMAPINFO*)(new BITMAP_INFO);
if (BitmapInfo == NULL){
MessageBox(NULL, "Bitmap Error", "Info", MB_OK);
return;
hbitmap= CreateDIBSection( hdc, BitmapInfo,
DIB_RGB_COLORS, &pbits, NULL, 0 );
HDC hMem = CreateCompatibleDC(hdc);
UINT cColors = GetDIBColorTable(hMem, 0, 16, bfo.bmColor);
SetDIBColorTable(hMem, 0, cColors, bfo.bmColor);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMem, hbitmap);
SelectObject(hMem, hOldBitmap);
BitBlt(hdc, 100, 150, 16, 16 , hMem, 0, 0, SRCCOPY);
DeleteDC(hMem);
ReleaseDC(hwnd, hMem);
void paint(HDC hdc, HWND hwnd){
BITMAP_INFO bfo;
HBITMAP hbitmap;
int dwn, acc = 16;
int accLoc, dnLoc = 100;
HDC hDc = CreateCompatibleDC(hdc);
memset(&bfo, 0, sizeof(bfo));
RGBQUAD palet[16];
BYTE cdata[] = {0xff, 0xff, 0xff,
0,0,0,
0xff,0,0,
0,0xff,0,
0,0,0xff,
0xf0,0xf0,0xf0,
0xf0,0xf0,0,
0xf0,0,0xf0,
0,0xf0,0xf0,
0xff,0,0xff,
0x3c,0x3c,0,
0x3c,0,0x3c,
0,0x3c,0x3c,
0xf0,0xf0,0,
0xf0,0,0xf0,
0,0xf0,0xf0};
int num = 16;
BYTE * pdata = &cdata[0];
int datasz = 3*num;
int count = 0;
RGBQUAD palette[16];
ZeroMemory(bfo.bmColor, sizeof(palette));
while(count < datasz/num ){
bfo.bmColor[count].rgbRed = *pdata++;
bfo.bmColor[count].rgbBlue = *pdata++;
bfo.bmColor[count].rgbGreen = *pdata++;
bfo.bmColor[count].rgbReserved = 0;
count++;
}
BYTE data[] = {1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,
1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,
1,1,2,2,3,3,3,2,2,3,3,3,2,2,1,1,
1,1,2,2,3,3,3,4,4,3,3,3,2,2,1,1,
1,1,2,2,3,3,3,4,4,3,3,3,2,2,1,1,
1,1,2,2,0,0,0,0,0,0,0,0,2,2,1,1,
1,1,2,2,0,0,0,0,0,0,0,0,2,2,1,1,
1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,
1,1,2,2,0,0,0,0,0,0,0,0,2,2,1,1,
1,1,2,2,2,2,2,2,2,2,2,2,2,2,1,1,
1,1,2,2,3,3,3,2,2,3,3,3,2,2,1,1,
1,1,2,2,3,3,3,4,4,3,3,3,2,2,1,1,
1,1,2,2,3,3,3,4,4,3,3,3,2,2,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
BITMAPINFO * BitmapInfo = (BITMAPINFO*)(new BITMAP_INFO);
if (BitmapInfo == NULL){
MessageBox(NULL, "Bitmap Error", "Info", MB_OK);
return;
}
for(int lp = 0 ; lp != 16; lp++){
BitmapInfo->bmiColors[lp].rgbBlue = bfo.bmColor[lp].rgbBlue;
BitmapInfo->bmiColors[lp].rgbGreen= bfo.bmColor[lp].rgbGreen;
BitmapInfo->bmiColors[lp].rgbRed = bfo.bmColor[lp].rgbRed;
BitmapInfo->bmiColors[lp].rgbReserved = 0;
}
BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo->bmiHeader.biBitCount = 4;
BitmapInfo->bmiHeader.biHeight = 16;
BitmapInfo->bmiHeader.biWidth = 16;
BitmapInfo->bmiHeader.biCompression = BI_RGB;
BitmapInfo->bmiHeader.biPlanes = 1;
hbitmap = CreateDIBSection(hDc, BitmapInfo, DIB_RGB_COLORS,
(PVOID*)&data, NULL, 0);
SelectObject(hDc, hbitmap);
GdiFlush();
StretchBlt(hdc, 250,250,16*5,16*5,hDc,0,0,16,16,MERGECOPY);
DeleteDC(hDc);
ReleaseDC(hwnd, hDc);
}
You must play with RGB values...
Just for an example, to create a red grid with CreateDIBSection()=>
HBITMAP hBitmapOld;
HDC hDC = GetDC(NULL);
HDC hDCMem = CreateCompatibleDC(hDC);
int nX = 800, nY = 600;
BITMAPINFO bi = {0};
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth = nX;
bi.bmiHeader.biHeight = nY;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = BI_RGB;
BYTE *pbBitmap;
HBITMAP hBitmap = CreateDIBSection(hDCMem, &bi, DIB_RGB_COLORS,
(void**)&pbBitmap, NULL, 0);
if (hBitmap)
{
hBitmapOld = (HBITMAP)SelectObject(hDCMem, hBitmap);
RGBQUAD *pRGB;
LONG nPixels;
for (pRGB = (RGBQUAD *)pbBitmap, nPixels = nX * nY; nPixels >= 0; +
+pRGB, --nPixels)
{
if ( nPixels%10 == 0 || (nPixels/800) %10 == 0)
pRGB->rgbRed = 255;
}
BitBlt(hDC, 0, 0, nX, nY, hDCMem, 0, 0, SRCCOPY);
SelectObject(hDCMem, hBitmapOld);
DeleteObject(hBitmap);
}
DeleteDC(hDCMem);
ReleaseDC(NULL, hDC);
http://msdn.microsoft.com/en-us/library/dd183494(VS.85).aspx
ppvBits [out]
A pointer to a variable that receives a pointer to the location of the
DIB bit values.
void *ppvBits;
hbitmap = CreateDIBSection(hDc, BitmapInfo, DIB_RGB_COLORS,
&ppvBits, NULL, 0);
CopyMemory(ppvBits, data, dataSize);
hth,
Friedel
Thanks, I did some research to get that far and it seems those few
changes have made the bitmap work. I just I have to manipulate the
data to see what I can do.