Re: Create compatible bitmap
You are loading a DIB (device independent bitmap) then trying to blit it to a specific device (not independent). You need to first convert your DIB to a device dependent bitmap (DDB) that is compatible with the device you intend to use (your display in this case). You do this with the un-aptly named CreateDIBBitmap() using a DC compatible with your display. See:
http://www.codeguru.com/cpp/g-m/bitm...icle.php/c1681
Re: Create compatible bitmap
Thanks for your response.
Uhm, well ... LOADING the bitmap (file) and then overwriting the file's data with my byte buffer very much DID work the way I described. But this is said detour I can't take in the final code. I tried using CreateDIBBitmap like you said.
Code:
BITMAPINFOHEADER bmih;
bmih.biSize = sizeof (BITMAPINFOHEADER);
bmih.biWidth = m_width;
bmih.biHeight = m_height;
bmih.biPlanes = 1;
bmih.biBitCount = 8;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = m_width*m_height;
if (0 == m_pBitmapInfo)
{
m_pBitmapInfo = (BITMAPINFO *) (new BYTE[sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD)]);
}
m_pBitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pBitmapInfo->bmiHeader.biWidth = m_width;
m_pBitmapInfo->bmiHeader.biHeight = m_height;
m_pBitmapInfo->bmiHeader.biPlanes = 1;
m_pBitmapInfo->bmiHeader.biBitCount = 8;
m_pBitmapInfo->bmiHeader.biCompression = BI_RGB;
m_pBitmapInfo->bmiHeader.biSizeImage = m_width*m_height;
m_pBitmapInfo->bmiHeader.biClrUsed = 0;
if (0 != m_pBitmapInfo)
{
for (int n=0; n < 256; n++)
{
m_pBitmapInfo->bmiColors[n].rgbBlue=datap[n];
m_pBitmapInfo->bmiColors[n].rgbGreen=datap[n];
m_pBitmapInfo->bmiColors[n].rgbRed=datap[n];
m_pBitmapInfo->bmiColors[n].rgbReserved=0;
}
}
CDC dcMem_display;
dcMem_display.CreateCompatibleDC(dc);
HDC hdc = dcMem_display;
HBITMAP hBmp = (HBITMAP)::CreateDIBitmap(hdc, &bmih, CBM_INIT, datap, m_pBitmapInfo, DIB_RGB_COLORS);
HBITMAP BitmapOld = (HBITMAP)SelectObject(dcMem_display, hBmp);
dc->StretchBlt(xOffset, yOffset, m_width*rectSizeX, m_height*rectSizeY, &dcMem_display, 0, 0, m_width, m_height, SRCCOPY);
dcMem_display.SelectObject(BitmapOld);
dcMem_display.DeleteDC();
But all I get with this, is a solid black rectangle drawn into my window.
Mac
Re: Create compatible bitmap
In this case, since you mentioned it's an 8-bit BMP, it appears that you are corrupting your bitmap by loading the pixel information into the color table area. An 8-bit BMP has a table of 256 DWORDS representing the colormap for this bitmap immediately following the header.
Re: Create compatible bitmap
I got it!
Went back to CreateDIBSection() from my original post, but initialized bmiColors like this:
Code:
for (int n=0; n < 256; n++)
{
m_pBitmapInfo->bmiColors[n].rgbBlue=n;
m_pBitmapInfo->bmiColors[n].rgbGreen=n;
m_pBitmapInfo->bmiColors[n].rgbRed=n;
m_pBitmapInfo->bmiColors[n].rgbReserved=0;
}
Thanks for the advice!
Mac