装载有PNG的Gdiplus的HICON质量低

时间:2016-02-18 17:09:15

标签: c++ listview winapi imagelist

我正在尝试将一些PNG图像加载到WinAPI ImageList中,作为要在ListView中显示的元素的图标。我用Gdiplus这样做,我遇到的问题是质量很糟糕。就像颜色深度减少一样。

我就是这样做的(在WinMain中调用的函数,就在循环之前):

HIMAGELIST hLarge;
HIMAGELIST hSmall;

hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
    GetSystemMetrics(SM_CYICON),
    ILC_MASK, 1, 1);

hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
    GetSystemMetrics(SM_CYSMICON),
    ILC_MASK, 1, 1);

ListView_SetImageList(hWndListView, hLarge, LVSIL_NORMAL);
ListView_SetImageList(hWndListView, hSmall, LVSIL_SMALL);

HICON hIconItem
Gdiplus::Bitmap *bitmap = new Gdiplus::Bitmap(image_path, 0);
bitmap->GetHICON(&hIconItem);
ImageList_AddIcon(hSmall, hiconItem);
ImageList_AddIcon(hLarge, hiconItem);

现在,我缺少什么,图片在哪里丢失信息?

This is how icons show up and below the real icons (in PNG)

我已将ILC_MASK更改为ILC_MASK | ILC_COLOR32。质量好一点,但没有反别名。

1 个答案:

答案 0 :(得分:2)

您的PNG很可能是32位颜色。在ImageList_Create()来电中,请使用标记ILC_COLOR32 | ILC_MASK,而不是ILC_MASK

根据MSDN,如果您未指定其中一个ILC_COLORxxx标记,则默认为ILC_COLOR4,即4位16色彩图形。这解释了您降低的图像质量。明确指定ILC_COLOR32将为您提供所需的全彩图标。

相关问题