private BitmapSource GetIcon(string file) { if (File.Exists(Envi.Root + "\\AppIcons\\" + Path.GetFileNameWithoutExtension(file) + ".png")) { return(new BitmapImage(new Uri(Envi.Root + "\\AppIcons\\" + Path.GetFileNameWithoutExtension(file) + ".png"))); } Icon icon = null; Icon[] splitIcons = null; try { using (var extractor = new IconExtractor(file)) { icon = extractor.GetIcon(0); } } catch (Exception) { return(null); } splitIcons = IconExtractor.SplitIcon(icon); if (splitIcons == null) { return(null); } foreach (var splitIcon in splitIcons) { if (splitIcon.Width == 256 && splitIcon.Height == 256) { icon = splitIcon; continue; } if (icon == null && splitIcon.Width == 32 && splitIcon.Height == 32) { icon = splitIcon; continue; } splitIcon.Dispose(); } iconStream = new MemoryStream(); icon.Save(iconStream); iconStream.Seek(0, SeekOrigin.Begin); return(BitmapFrame.Create(iconStream)); }
private BitmapSource GetIcon(string file) { if (File.Exists(Envi.Root + "\\AppIcons\\" + Path.GetFileNameWithoutExtension(file) + ".png")) { return new BitmapImage(new Uri(Envi.Root + "\\AppIcons\\" + Path.GetFileNameWithoutExtension(file) + ".png")); } Icon icon = null; Icon[] splitIcons = null; try { using (var extractor = new IconExtractor(file)) { icon = extractor.GetIcon(0); } } catch (Exception) { return null; } splitIcons = IconExtractor.SplitIcon(icon); if (splitIcons == null) return null; foreach (var splitIcon in splitIcons) { if (splitIcon.Width == 256 && splitIcon.Height == 256) { icon = splitIcon; continue; } if (icon == null && splitIcon.Width == 32 && splitIcon.Height == 32) { icon = splitIcon; continue; } splitIcon.Dispose(); } iconStream = new MemoryStream(); icon.Save(iconStream); iconStream.Seek(0, SeekOrigin.Begin); return BitmapFrame.Create(iconStream); }