作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这是我当前的代码,但在转换为 BITMAPINFOHEADER 时会导致错误:
/* Create the bitmap */
BITMAPINFO bmpinfo;
ZeroMemory(&bmpinfo, sizeof(bmpinfo));
BITMAPV5HEADER bmpheader;
ZeroMemory(&bmpheader, sizeof(bmpheader));
bmpheader.bV5Size = sizeof(BITMAPV5HEADER);
bmpheader.bV5Width = width;
bmpheader.bV5Height = height;
bmpheader.bV5Planes = 1;
bmpheader.bV5BitCount = 32;
bmpheader.bV5Compression = BI_BITFIELDS;
bmpheader.bV5SizeImage = width*height*4;
bmpheader.bV5RedMask = 0x00FF0000;
bmpheader.bV5GreenMask = 0x0000FF00;
bmpheader.bV5BlueMask = 0x000000FF;
bmpheader.bV5AlphaMask = 0xFF000000;
bmpheader.bV5CSType = 0x57696e20; // LCS_WINDOWS_COLOR_SPACE
bmpheader.bV5Intent = LCS_GM_BUSINESS;
bmpinfo.bmiHeader = reinterpret_cast<BITMAPINFOHEADER>(bmpheader);
void* converted = NULL;
HDC screen = GetDC(NULL);
HBITMAP result = CreateDIBSection(screen, &bmpinfo, DIB_RGB_COLORS, &converted, NULL, 0);
ReleaseDC(NULL, screen);
// Image data filled here
我怎样才能成功做到这一点?
最佳答案
BITMAPINFO
不是真正的结构,它更像是关于颜色映射如何跟随标题的文档。只需将 BITMAPV5HEADER
直接传递给 CreateDIBSection:
HBITMAP result = CreateDIBSection(screen, reinterpret_cast<BITMAPINFO *>(&bmpheader), DIB_RGB_COLORS, &converted, NULL, 0);
关于c++ - 如何使用 BITMAPV5HEADER header 创建位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4455655/
我是一名优秀的程序员,十分优秀!