Professional Documents
Culture Documents
The following Visual C++ code segment can be used to save a HBITMAP object in to
BMP file format.
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = bmp.bmWidth;
pbmi->bmiHeader.biHeight = bmp.bmHeight;
pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
if (cClrBits < 24)
pbmi->bmiHeader.biClrUsed = (1<<cClrBits);
if (!lpBits) {
AfxMessageBox("writeBMP::Could not allocate memory");
return;
}
// Free memory.
GlobalFree((HGLOBAL)lpBits);
}