【发布时间】:2011-02-14 21:59:48
【问题描述】:
我正在使用 GDI+ 显示位图。从 DLL 资源加载位图后,我使用 TransparentBlt 将背景颜色(蓝色 - #0000FF)设置为透明。在 Windows Vista 及更高版本上,这可以按预期工作。
但是,在我们正在测试的 Windows XP 系统上,此功能仅在显示任何工具提示(例如 IE 中的“标题”属性,或将鼠标悬停在文件上时显示的 Windows 资源管理器的工具提示等)时才有效。其余时间背景颜色仍为蓝色。
以前有没有人遇到过这种情况,或者知道如何阻止这种情况发生并使蓝色正确透明?
编辑:经过进一步调查,我发现将 Windows XP 中的颜色深度设置为 16 位颜色而不是 32 位颜色会导致 TransparentBlt 再次开始正常工作。显然这不是一个理想的解决方案,指定必须使用什么颜色深度,但这是否暗示了可能发生的事情?
Edit2:包含代码示例。
m_pGDIBitmap = new Gdiplus::Bitmap(_Module.m_hInst, MAKEINTRESOURCE(lImageResource));
m_hMemDC = CreateCompatibleDC(hdc);
Gdiplus::Graphics myGraphics(m_hMemDC);
myGraphics.DrawImage(m_pGDIBitmap,
Gdiplus::Rect(0, 0, m_pGDIBitmap->GetWidth(), m_pGDIBitmap->GetHeight()),
0,
0,
m_pGDIBitmap->GetWidth(),
m_pGDIBitmap->GetHeight(),
Gdiplus::UnitPixel, &imAtt);
SetStretchBltMode(hdc, HALFTONE);
SetBrushOrgEx(hdc, rcBounds.left, rcBounds.top, NULL);
TransparentBlt(hdc, rcBounds.left, rcBounds.top, iScaledWidth, iScaledHeight, m_hMemDC, 0, 0, iBitmapWidth, iBitmapHeight, GetPixel(m_hMemDC, 0, 0));
【问题讨论】:
-
愚蠢的问题,但如果你选择不同的颜色会发生同样的情况吗?
-
不幸的是,是的。我尝试了黑色,结果相同。