alx
alx

Reputation: 57

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);

Upvotes: 4

Views: 3942

Answers (3)

user350966
user350966

Reputation: 19

You can find a working how-to here: http://support.microsoft.com/?scid=kb;en-us;319350&x=14&y=9

Upvotes: 1

arbiter
arbiter

Reputation: 9605

Did you tried the following?

Icon LargeIcon = Icon.ExtractAssociatedIcon(fileName);
Icon SmallIcon = new Icon(LargeIcon, 16, 16);

Upvotes: 3

Icebob
Icebob

Reputation: 1206

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

Upvotes: 2

Related Questions