Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8191115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:50:53+00:00 2026-06-07T03:50:53+00:00

I need to extract an icon from Windows Shell from a specific file extension.

  • 0

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:

screenshot

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:50:55+00:00Added an answer on June 7, 2026 at 3:50 am
    HICON ico = NULL;
    pList->GetIcon(shfi.iIcon, ILD_TRANSPARENT, &ico);
    
    ICONINFO ii = {0};
    GetIconInfo(ico, &ii);
    
    Gdiplus::Bitmap bmpIcon(ii.hbmColor, NULL);
    Gdiplus::Rect rectBounds(0, 0, bmpIcon.GetWidth(), bmpIcon.GetHeight() );
    
    BitmapData bmData;
    bmpIcon.LockBits(&rectBounds, ImageLockModeRead, bmpIcon.GetPixelFormat(), &bmData);
    
    Bitmap bmp(bmData.Width, bmData.Height, bmData.Stride, PixelFormat32bppARGB, (BYTE*)bmData.Scan0);
    
    bmpIcon.UnlockBits(&bmData);
    

    bmp now contain a valid transparent/alphablended bitmap from HICON.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract the icon from a windows shortcut (.lnk) file (or find
I need help on how to extract the various images from an icon file
I need to extract all the tags from an HTML file, In such a
I need to extract all MP3 titles from a fuzzy list in a list.
I need to extract the zip code from a string. The string looks like
I need to extract data from a structure and put it into a list,
I need to extract data from a source that presents it in one of
I need to extract the RSA public key from a RSA private key using
I need to extract Asia from this array. How can i do that. Here
i have a rpm package, and i need to extract some files from it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.