To draw a bitmap that is provided as DIB (Device Independant Bitmap), it must be converted to a device (usually: screen) compatible DDB (Device Dependant Bitmap). This can be done using the
CreateDIBitmap()[
^] GDI function:
LPBITMAPINFOHEADER lpBIH = static_cast<LPBITMAPINFOHEADER>(lpData);
unsigned nColorSize = lpBIH->biClrUsed * sizeof(RGBQUAD);
if (lpBIH->biBitCount <= 8)
{
if (0 == nColorSize)
nColorSize = (lpBIH->biBitCount << 1) * sizeof(RGBQUAD);
}
else if (BI_BITFIELDS == lpBIH->biCompression)
nColorSize = 3 * sizeof(DWORD);
LPBYTE lpBiBuf[sizeof(BITMAPINFO) + 255 * sizeof(RGBQUAD)];
LPBITMAPINFO = lpBI reinterpret_cast<LPBITMAPINFO>(lpBiBuf);
::CopyMemory(lpBI, lpBIH, sizeof(BITMAPINFO));
lpBI->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
if (nColorSize)
::CopyMemory(lpBI->bmiColors, static_cast<LPBYTE>(lpData) + lpBIH->biSize, nColorSize);
HDC hScreen = ::GetDC(NULL);
HBITMAP hBitmap = ::CreateDIBitmap(
hScreen, lpBIH, CBM_INIT, static_cast<LPBYTE>(lpData) + lpBIH->biSize + nColorSize,
lpBI, DIB_RGB_COLORS); ::ReleaseDC(NULL, hScreen);
The created bitmap can be now be selected into a device context and drawn using one of the blitter functions.