首页 文章

装载有PNG的Gdiplus的HICON质量低

提问于
浏览
0

我正在尝试将一些PNG图像加载到WinAPI ImageList 中,作为要在_1557287中显示的元素的图标 . 我用 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 回答

  • 2

    您的PNG很可能是32位颜色 . 在 ImageList_Create() 调用中,仅使用标志 ILC_COLOR32 | ILC_MASK ,而不是 ILC_MASK .

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

相关问题