无法从 GDI 获取的 HBITMAP 创建单色位图位图::GetHBITMAP
我无法使用 SetBkColor() > 创建 24BPP 彩色图像的单色蒙版BitBlt[SRCCOPY]。面具最终变成完全黑色。仅当我使用 LoadImage() 来获取 HBITMAP 时,整个事情才有效。
Bitmap img(L"Ball.bmp");
HBITMAP hBM;
img.GetHBITMAP(Color::White, &hBM);
//hBM = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
.
.
SelectObject(hDCSrc, hBM);
SetBkColor(RGB(0xFF, 0xFF, oxFF));
BitBlt(hDCMem, 0, 0, img.GetWidth(), img.GetHeight(), hDCSrc, 0, 0, SRCCOPY);
//hDCMem is copletely black; but OK when using LoadImage() instead
其他有同样问题的人建议使用 Graphics::GetHDC 并使用此 DC 执行所需操作作为解决方法。但为什么它没有发挥应有的作用。
即使这个解决方法也不起作用。请帮忙:(
I am unable to Create a Monochrome Mask for a 24BPP Colour image with SetBkColor() > BitBlt[SRCCOPY]. The Mask ends up completely Black. The entire thing works only if I use LoadImage() instead to get the HBITMAP.
Bitmap img(L"Ball.bmp");
HBITMAP hBM;
img.GetHBITMAP(Color::White, &hBM);
//hBM = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL));
.
.
SelectObject(hDCSrc, hBM);
SetBkColor(RGB(0xFF, 0xFF, oxFF));
BitBlt(hDCMem, 0, 0, img.GetWidth(), img.GetHeight(), hDCSrc, 0, 0, SRCCOPY);
//hDCMem is copletely black; but OK when using LoadImage() instead
Other people with the same problem have suggested using Graphics::GetHDC and doing the required with this DC as a workaround. But why does it not work as it should.
Even this workaround din' work. Please help :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决了:
如何生成单色位32 位位图的掩码
Solved it:
How to genrate a monochrome bit mask for a 32bit bitmap
是的,您可以仅使用 GDI 调用从 24bpp 位图构建单色蒙版,而无需扫描各个像素,但您必须决定将 24bpp 位图中的哪种颜色视为透明。请参阅下面的代码:
您还可以使用
TransparentBlt()
函数来完成此操作。Yes, you can construct a monochrome mask out of an 24bpp bitmap with GDI calls only and without scanning the individual pixels, but you have to decide which color in the 24bpp bitmap you want to treat as transparent. See the code below:
You could also accomplish this with the
TransparentBlt()
function.