C#.codebox 2
WPF – How to extract an icon from a file?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | using System.Windows.Media; using IconImage = System.Drawing.Icon; using System.Windows.Media.Imaging; using System.Windows.Controls; //Extracts the icon from a file and returns it as ImageSource. public ImageSource ExtractIconFromFile(string Location) { Image myImage = new Image(); //Get icon IconImage myIconImage; myIconImage = IconImage.ExtractAssociatedIcon(Location); MemoryStream strm = new MemoryStream(); myIconImage.Save(strm); IconBitmapDecoder BMPDec = new IconBitmapDecoder(strm, BitmapCreateOptions.None, BitmapCacheOption.Default); myImage.Source = BMPDec.Frames[0]; strm.Close(); return myImage.Source; } |
