多少内存应该分配使用功能的GetDIBits从HBITMAP收到的DIB数据? [英] How much memory should be allocated for the DIB data received from HBITMAP using GetDIBits function?
问题描述
多少内存使用功能的GetDIBits从HBITMAP收到的DIB数据应如何分配?
How much memory should be allocated for the DIB data received from HBITMAP using GetDIBits function?
该功能的GetDIBits在MSDN描述如下:
The GetDIBits function is described in MSDN as follow:
int GetDIBits(
__in HDC hdc,
__in HBITMAP hbmp,
__in UINT uStartScan,
__in UINT cScanLines,
__out LPVOID lpvBits,
__inout LPBITMAPINFO lpbi,
__in UINT uUsage
);
不过,缓冲区来接收lpvBits必须在调用之前的GetDIBits分配的数据,因为的GetDIBits不会自动分配这一点。
However, the buffer to receive data lpvBits must be allocated before calling GetDIBits, because GetDIBits doesn't allocate this automatically.
问题是,有多少内存应该分配给接收DIB数据?假设该HBITMAP的宽度和放大器;高度Bmp_Width&放大器; Bmp_Height;和位图是32位(RGBA)
The question is how much memory should be allocated to receive the DIB data? Supposed that the HBITMAP has width&height as Bmp_Width&Bmp_Height; and the bitmap is 32-bit (RGBA).
推荐答案
我觉得最简单的方法是调用GetObject()函数(和BTW获取图像位):
I think the simplest way is calling GetObject() function (And BTW to get the image bits):
BITMAP bmpObject;
GetObject(hBitmap, sizeof(BITMAP), &bmpObject);
然后你只需使用位图字段:
Then you simply use the Bitmap Fields:
LONG size = bmpObject.bmWidthBytes * bmpObject.bmHeight;
注意对齐whem处理图像字节!
Be aware of alignment whem processing image bytes!
希望这会有所帮助!
这篇关于多少内存应该分配使用功能的GetDIBits从HBITMAP收到的DIB数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!