I need to extract an icon from Windows Shell from a specific file extension.
After extraction I need to save it as PNG file with transparency.
But I don’t know what has happened, it looks like the transparency is corrupted.
Please see the attached image(gray color is real transparency).
Windows shell display this icon correctly, but some artifacts are also visible (like shadow or glow). See the screenshot below:

HRESULT hr = ::SHGetFileInfoA(pszPath, dwAttributes, &shfi, sizeof(shfi), SHGFI_SYSICONINDEX | SHGFI_LARGEICON );
if (!SUCCEEDED(hr))
return 0;
ATL::CComPtr<IImageList> pList;
HRESULT h2 = ::SHGetImageList(uState, IID_IImageList, (void**)&pList);
if (!SUCCEEDED(h2))
return 0;
int count = 0;
pList->GetImageCount(&count);
if (count <= shfi.iIcon)
return 0;
HICON ico = ImageList_GetIcon(IImageListToHIMAGELIST(pList), shfi.iIcon, ILD_TRANSPARENT);
Gdiplus::Bitmap bmp(ico);
Graphics *pGraphics = Graphics::FromImage(&bmp);
IMAGELISTDRAWPARAMS pimldp = {0};
pimldp.hdcDst = pGraphics->GetHDC();
pimldp.cbSize = sizeof IMAGELISTDRAWPARAMS;
pimldp.himl = IImageListToHIMAGELIST(pList);
pimldp.i = shfi.iIcon;
pimldp.x = 0;
pimldp.y = 0;
pimldp.cx = cx;
pimldp.cy = cy;
pimldp.yBitmap = 0;
pimldp.xBitmap = 0;
pimldp.fStyle = ILD_IMAGE | ILD_SCALE /*| ILD_PRESERVEALPHA*/ ;
ImageList_DrawIndirect(&pimldp);
CLSID clsid;
GetEncoderClsid(L"image/png", &clsid);
bmp.Save(L"d:\\test.png", &clsid);
::ShellExecuteA(NULL, "open", "d:\\test.png", "", "d:\\", SW_NORMAL);
pGraphics->ReleaseHDC(pimldp.hdcDst);
::DestroyIcon(ico);
bmpnow contain a valid transparent/alphablended bitmap fromHICON.