// 1. 获取DC的HBITMAP
HBITMAP hBitmap = (HBITMAP)::GetCurrentObject(hDC, OBJ_BITMAP);
if(0 == hBitmap)
{
return false;
}
// 2. 通过HBITMAP获取BITMAP
BITMAP bitmap;
::GetObject(hBitmap, sizeof(BITMAP), &bitmap);
// 3. 使用BITMAP构建BITMAPINFOHEADER
bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biBitCount = bitmap.bmBitsPixel;
bitmapInfoHeader.biCompression = BI_RGB;
bitmapInfoHeader.biPlanes = bitmap.bmPlanes;
bitmapInfoHeader.biWidth = bitmap.bmWidth;
bitmapInfoHeader.biHeight = bitmap.bmHeight;
unsigned int nBytePerLine = (bitmapInfoHeader.biWidth * bitmapInfoHeader.biBitCount + 7) / 8;
nBytePerLine = (nBytePerLine + 3) / 4 * 4;
bitmapInfoHeader.biSizeImage = nBytePerLine * bitmapInfoHeader.biHeight;
// 4. 获取颜色表
HPALETTE hPalette = (HPALETTE)::GetCurrentObject(hDC, OBJ_PAL);
int nEntries = 0;
::GetObject(hPalette, sizeof(WORD), &nEntr
HDC 保存为BMP图片步骤
最新推荐文章于 2020-10-04 14:59:25 发布