我正在使用GDI +显示位图。从DLL资源加载位图后,我使用TransparentBlt将背景颜色(蓝色 - #0000FF)设置为透明。在Windows Vista和更高版本上,按预期工作。为什么GDI +颜色会根据工具提示是否可见而变化?
但是,在我们测试的Windows XP系统上,只有在显示任何工具提示(例如IE中的“title”属性,或将鼠标悬停在文件上时显示的Windows资源管理器的工具提示)时才能使用。剩下的时间背景颜色仍然是蓝色的。
有没有人遇到过这种情况,或知道一种方法来阻止这种情况的发生,并使蓝色适当变得透明?
编辑:经过进一步调查后,我发现将Windows XP中的颜色深度设置为16位颜色而不是32位颜色,导致TransparentBlt再次开始正常工作。显然,这不是一个理想的解决方案,指定必须使用哪种颜色深度,但是这是否会提示可能发生的情况?
编辑2:包括代码示例。
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));
愚蠢的问题,但如果你选择了不同的颜色,也会发生同样的问题吗? – 2010-05-03 05:02:48
不幸的是。我用同样的结果尝试黑色。 – dlanod 2010-05-03 07:00:54