Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract a correct 16x16 icon assigned to a file?

I tied SHGetFileInfo and ExtractIconEx, both return a normal 32x32 icon and 16x16 with only 16 colors, and it looks awful. How do I extract a full color icon?

My code

SHFILEINFO shinfo = new SHFILEINFO();
IntPtr hImgSmall = SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON);
Icon icon = (Icon)System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone();
DestroyIcon(shinfo.hIcon);
like image 660
alx Avatar asked Jan 24 '23 11:01

alx


2 Answers

I tried this example link text and works.....got 16*16 with alpha channel. Try it.

like image 98
Icebob Avatar answered Feb 04 '23 12:02

Icebob


Did you tried the following?

Icon LargeIcon = Icon.ExtractAssociatedIcon(fileName);
Icon SmallIcon = new Icon(LargeIcon, 16, 16);
like image 39
arbiter Avatar answered Feb 04 '23 12:02

arbiter