c++ - DrawIconEx 留下 mask 伪影

标签 c++ windows winapi icons

我正在使用 IImageListSHGetFileInfo 为任何给定路径提取巨型图标。一旦我有了它,然后我使用 DrawIconExHICON 渲染到 HBITMAP 中,最终使用 GDI+ Bitmap 渲染,并且图形 对象。

现在,这一切都很好,除了当我对位图进行最终渲染时,最左边的边缘上总是有一个黑色的伪影。对于我得到的几乎所有图标都是如此,并且始终位于左边缘。

What I see in explorer.exe on left, what my drawn icon looks like right

知道黑线是从哪里来的吗?

我使用的代码大致是:

1。提取图标:

// Get the image list index of the icon
SHFILEINFO sfi;
if (!SHGetFileInfo(pszPath, 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX)) return NULL;

// Get the jumbo image list
IImageList *piml;
if (FAILED(SHGetImageList(SHIL_JUMBO, IID_PPV_ARGS(&piml)))) return NULL;

// Extract an icon
HICON hicon;
piml->GetIcon(sfi.iIcon, ILD_SCALE|ILD_TRANSPARENT, &hicon);
return hicon;

2。生成位图

HDC hDC = GetDC(NULL);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hMemBmp = CreateCompatibleBitmap(hDC, x, y);
HBITMAP hResultBmp = NULL;
HGDIOBJ hOrgBMP = SelectObject(hMemDC, hMemBmp);

HBRUSH hbr = CreateSolidBrush(bg);

RECT rr = { 0, 0, 256, 256 }; // jumbo icons
FillRect(hMemDC, &rr, hbr);
DeleteBrush(hbr);
DrawIconEx(hMemDC, 0, 0, hicon, size, size, 0, NULL, DI_NORMAL);

hResultBmp = hMemBmp;
hMemBmp = NULL;

SelectObject(hMemDC, hOrgBMP);
return hResultBitmap;

3。将 GDI+ 位图呈现为“窗口位图”:

Bitmap *b = ::New Bitmap(hResultBitmap, NULL);

Graphics    graphics(hdc);
graphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);

SolidBrush  bgbrush(Color(255, 255, 255, 255));
Rect r(0, 0, hwnd_w, hwnd_h);
graphics.FillRectangle(&bgbrush, r);

graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic);
Rect r(5, 5, 128, 128);
graphics.DrawImage(dpd->image_to_draw, r);

最佳答案

哇,我昨晚又玩了一会儿。它是 IImageList::GetIcon 中的 ILD_SCALE

摆脱它,一切都会恢复正常。去图......

1。提取图标:

// Get the image list index of the icon
SHFILEINFO sfi;
if (!SHGetFileInfo(pszPath, 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX)) return NULL;

// Get the jumbo image list
IImageList *piml;
if (FAILED(SHGetImageList(SHIL_JUMBO, IID_PPV_ARGS(&piml)))) return NULL;

// Extract an icon
HICON hicon;
piml->GetIcon(sfi.iIcon, ILD_TRANSPARENT, &hicon);
return hicon;

关于c++ - DrawIconEx 留下 mask 伪影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12471020/

相关文章:

windows - LibreOffice exe 文件在 windows 中将 word 转换为 pdf

javascript - InnoSetup - 有没有办法为 Internet Explorer 手动创建 cookie?

c++ - 任何构建工具都可以自动理解 C++ 项目中的文件依赖关系?

c++ - c++11 std::ref 是如何工作的?

python - 从 C++ 调用的 python 方法返回列表

c - Visual Studio 2012 中的 WinAPI 文档

c++ - DXGI 文本输出轨迹

c++ - 在对象中存储和检索不同的数据类型

c++ - 从一个目录中读取许多小文件会有多大问题?

c - Win Api-SetEvent和WaitForSingleObject,线程之间的内存同步