// 从HDC 获取 HBitmap
STDMETHOD(ExportHBitmap)(ULONG_PTR* o_hBitmap)
{
HBITMAP hBmp = NULL;
HANDLE hOld;
HDC hMemDC = NULL;
long lRectPara[4];
GetWndRect(lRectPara);
long nWidth = lRectPara[2];
long nHeight = lRectPara[3];
hMemDC = CreateCompatibleDC(m_hDC);
BITMAPINFO bi;
ZeroMemory(&bi, sizeof(BITMAPINFO));
// 获得颜色深度
int iBitsPerPixel = CDC::FromHandle(m_hDC)->GetDeviceCaps(BITSPIXEL);
// 设置每个颜色占位数
if (iBitsPerPixel <= 8)
{
iBitsPerPixel = 8;
}
else if (iBitsPerPixel <= 16)
{
iBitsPerPixel = 16;
}
else if (iBitsPerPixel <= 24)
{
iBitsPerPixel = 24;
}
else
{
iBitsPerPixel = 32;
}
// 设置DIB位图需要的BITMAPINFO结构
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = iBitsPerPixel;
bi.bmiHeader.biWidth = nWidth;
bi.bmiHeader.biHeight = -nHeight;
bi.bmiHeader.biSizeImag
获取HBITMAP,导出带透明度的png图片
最新推荐文章于 2023-03-29 16:33:12 发布