DrawIconEx留下面具工件 [英] DrawIconEx leaving mask artifacts
问题描述
我使用 IImageList
和 SHGetFileInfo
提取任何给定路径的巨型图标。一旦我有了,我然后使用 DrawIconEx $>将
HICON
变成 HBITMAP
c $ c>用于使用GDI + 位图
和图形
对象进行最终渲染。
I'm extracting jumbo icons for any given path using IImageList
and SHGetFileInfo
. Once I have that, I then render the HICON
into a HBITMAP
using DrawIconEx
for eventual rendering with GDI+ Bitmap
and Graphics
objects.
现在,这一切都很好,除了当我做位图的最终渲染时,左边缘总是有一个黑色的神器。
Now, this all works great, except that when I do the final rendering of the bitmap, the very left edge always has a black artifact on it. This is true for pretty much any icon I get, and is always the left edge.
暗线可能来的任何想法从?
Any ideas where the dark line could be coming from?
我使用的代码大致是:
// 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。生成位图
2. Generate Bitmap
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 +位图映射为窗口位图:
3. Render GDI+ Bitmap to "window bitmap":
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
。
Wow, I spent another while last night playing with it. It's the ILD_SCALE
in IImageList::GetIcon
.
摆脱这一切,它一切正常完美再次。 Go figure ...
Get rid of that and it all works perfectly fine again. Go figure …
// 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;
这篇关于DrawIconEx留下面具工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!