Extract the correct 16x16 icon assigned to a file?

I linked SHGetFileInfo and ExtractIconEx, both return a normal 32x32 and 16x16 icon with only 16 colors, and it looks awful. How to 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);
+3
source share
3 answers

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

+4
source

Have you tried the following?

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

Source: https://habr.com/ru/post/1711902/


All Articles