DrawIconEx laissant des artefacts de masque

IImageList icons jumbo pour n’importe quel chemin en utilisant IImageList et SHGetFileInfo . Une fois que j’ai cela, je rend ensuite le HICON dans un HBITMAP utilisant DrawIconEx pour un rendu éventuel avec les objects Bitmap et Graphics GDI +.

Maintenant, tout fonctionne très bien, sauf que lorsque je fais le rendu final du bitmap, le bord gauche a toujours un artefact noir. Ceci est vrai pour quasiment n’importe quelle icône que j’obtiens, et c’est toujours le bord gauche.

Ce que je vois dans explorer.exe à gauche, à quoi ressemble mon icône dessinée

Des idées d’où pourrait provenir la ligne noire?

Le code que j’utilise est grosso modo:

1. Icône d’extraction:

 // 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. Générer un 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. Rendez GDI + Bitmap en “bitmap de fenêtre”:

 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); 

    Wow, j’ai passé une autre nuit hier soir à jouer avec elle. C’est l’ ILD_SCALE dans IImageList::GetIcon .

    Débarrassez-vous de cela et tout fonctionne parfaitement bien à nouveau. Allez comprendre …

    1. Icône d’extraction:

     // 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;