static void Main(string[] args) { List <Image> imagesArray = new System.Collections.Generic.List <Image>(); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"C:\CosaHelperLib"); foreach (System.IO.FileInfo file in dir.GetFiles()) { String ext = file.Extension; Console.WriteLine(file.FullName); if (ext.Equals(".ico")) { Stream iconStream = new FileStream(file.FullName, FileMode.Open); IconBitmapDecoder decoder = new IconBitmapDecoder(iconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); foreach (var item in decoder.Frames) { var src = new System.Windows.Media.Imaging.FormatConvertedBitmap(); src.BeginInit(); src.Source = item; src.EndInit(); Console.WriteLine(file.FullName + '_' + src.PixelHeight + 'X' + src.PixelWidth); //Console.WriteLine("Pixel Width: " + src.PixelWidth); //Console.WriteLine("Pixel Height: " + src.PixelHeight); //Console.WriteLine("Pixel Width: " + src.PixelWidth); Console.WriteLine("Alpha Channel Threshold: " + src.AlphaThreshold); } } Console.WriteLine(); } Console.Read(); }
/// <summary> /// Method loads all icon sizes from icon and sets icon with max size to image /// </summary> private void _SetMaxSizeIconToImage() { Uri iconUri = new Uri(ICON_PATH); // load icon StreamResourceInfo iconInfo = Application.GetResourceStream(iconUri); Stream iconStream = iconInfo.Stream; IconBitmapDecoder iconBitmapDecoder = new IconBitmapDecoder(iconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); // if icon file contains more than 1 size - find frame with max size if (iconBitmapDecoder.Frames.Count > 1) { double maxHeight = 0; double maxWidth = 0; BitmapFrame sourceFrame = default(BitmapFrame); foreach (BitmapFrame bitmapFrame in iconBitmapDecoder.Frames) { if (bitmapFrame.Height > maxHeight && bitmapFrame.Width > maxWidth) { sourceFrame = bitmapFrame; // save found frame in sourceFrame maxHeight = bitmapFrame.Height; maxWidth = bitmapFrame.Width; } } image.Source = sourceFrame; // set max size frame as image source } }
public static ImageSource RetriveImage(string imagePath) { Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(imagePath); switch (imagePath.Substring(imagePath.Length - 3)) { case "jpg": { JpegBitmapDecoder jpegBitmapDecoder = new JpegBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(jpegBitmapDecoder.Frames[0]); } case "bmp": { BmpBitmapDecoder bmpBitmapDecoder = new BmpBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(bmpBitmapDecoder.Frames[0]); } case "png": { PngBitmapDecoder pngBitmapDecoder = new PngBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(pngBitmapDecoder.Frames[0]); } case "ico": { IconBitmapDecoder iconBitmapDecoder = new IconBitmapDecoder(manifestResourceStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(iconBitmapDecoder.Frames[0]); } default: return(null); } }
private static BitmapSource IconDecoder(string fileName, double width) { // // TODO: Try and get the highest-bit image in the set. // IconBitmapDecoder decoder = new IconBitmapDecoder(new Uri(fileName, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnDemand); BitmapFrame closestMatch = null; double closestWidth = double.PositiveInfinity; foreach (BitmapFrame each in decoder.Frames) { double widthDiff = Math.Abs(each.Width - width); if (widthDiff < closestWidth) { closestMatch = each; closestWidth = widthDiff; } // If we already have an exact match, break out of the loop. if (widthDiff == 0) { break; } } return(closestMatch); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { try { if (value == null) { return(null); } // The icon decoder does not work on XP. if (Environment.OSVersion.Version <= OSVersions.Win_XP_64) { return(null); } string source = value.ToString(); IconBitmapDecoder decoder = new IconBitmapDecoder(new Uri(source, UriKind.Absolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnDemand); foreach (BitmapFrame each in decoder.Frames) { if (each.Width == 16 && each.Height == 16) { return(each); } } return(decoder.Frames[0]); } catch { return(null); } }
public override bool View(DecompilerTextView textView) { try { AvalonEditTextOutput output = new AvalonEditTextOutput(); Data.Position = 0; IconBitmapDecoder decoder = new IconBitmapDecoder(Data, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); foreach (var frame in decoder.Frames) { output.Write(String.Format("{0}x{1}, {2} bit: ", frame.PixelHeight, frame.PixelWidth, frame.Thumbnail.Format.BitsPerPixel)); AddIcon(output, frame); output.WriteLine(); } output.AddButton(Images.Save, "Save", delegate { Save(null); }); textView.ShowNode(output, this); return(true); } catch (Exception) { return(false); } }
public AboutTabVM(AppVM app) : base(app, "关于") { var decoder = new IconBitmapDecoder(new Uri("pack://application:,,,/ConfuserEx.ico"), BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand); Icon = decoder.Frames.First(frame => frame.Width == 64); }
public override bool View(TabPageModel tabPage) { try { AvalonEditTextOutput output = new AvalonEditTextOutput(); using var data = OpenStream(); if (data == null) { return(false); } IconBitmapDecoder decoder = new IconBitmapDecoder(data, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); foreach (var frame in decoder.Frames) { output.Write(String.Format("{0}x{1}, {2} bit: ", frame.PixelHeight, frame.PixelWidth, frame.Thumbnail.Format.BitsPerPixel)); AddIcon(output, frame); output.WriteLine(); } output.AddButton(Images.Save, Resources.Save, delegate { Save(null); }); tabPage.ShowTextView(textView => textView.ShowNode(output, this)); tabPage.SupportsLanguageSwitching = false; return(true); } catch (Exception) { return(false); } }
public static byte[] GetIcon(System.IO.Stream iconStream) { byte[] iconBytes = null; IconBitmapDecoder decoder = new IconBitmapDecoder( iconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); // loop through images inside the file foreach (BitmapFrame frame in decoder.Frames) { // save file as PNG BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(frame); int size = frame.PixelHeight; // haven't tested the next lines - include them for bitdepth // See RenniePet's answer for details // var depth = frame.Thumbnail.Format.BitsPerPixel; // var path = outPath + fileName + size + depth +".png"; using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { encoder.Save(ms); iconBytes = ms.ToArray(); } } return(iconBytes); }
private StackPanel SetHeader(string title, string filename) { StackPanel stackPanel = new StackPanel(); Uri uri = new Uri(@"pack://*****:*****@"pack://application:,,,/Resources/Close.ico", UriKind.RelativeOrAbsolute); Image close = new Image(); close.Source = ((BitmapDecoder)(IconBitmapDecoder.Create(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default))).Frames[0]; Button closeButton = new Button(); closeButton.Content = close; closeButton.Margin = new Thickness(10, 0, 0, 0); title = title.Replace(' ', '_'); closeButton.Name = title; closeButton.Click += new RoutedEventHandler(closeButton_Click); closeButton.Height = 12; closeButton.Width = 12; closeButton.ToolTip = "Close Tab"; stackPanel.Orientation = Orientation.Horizontal; stackPanel.Children.Add(image); stackPanel.Children.Add(textBlock); stackPanel.Children.Add(closeButton); return(stackPanel); }
public MainWindow() { try { InitializeComponent(); } catch (Exception ex) { Logging.LogException(ex); throw; } EventManager.RegisterClassHandler(typeof(TreeViewItem), Mouse.MouseDownEvent, new MouseButtonEventHandler(OnTreeViewItemMouseDown), false); try { IconBitmapDecoder ibd = new IconBitmapDecoder( new Uri(@"pack://application:,,/DafuscatorIcon.ico", UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.Default); Icon = ibd.Frames[0]; } catch (Exception ex) { } SkinManager.SkinId = SkinId.OfficeBlack; SetWindowTitle(); Initialize(); }
/// <summary> /// Extracts a each image from an ico field. /// </summary> /// <param name="path">The path to the ico</param> /// <returns>Each image from inside the ico file</returns> public static List <ImageSource> GetIcoImages(string path) { List <ImageSource> ret = new List <ImageSource>(); if (!path.StartsWith("pack://") && !path.Contains('\\') && !path.Contains('/')) { path = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/" + path + ".ico"; } var iconUri = new Uri(path, UriKind.RelativeOrAbsolute); try { var iconDecoder = new IconBitmapDecoder(iconUri, BitmapCreateOptions.None, BitmapCacheOption.Default); // no image found if (iconDecoder.Frames.Count == 0) { return(ret); } BitmapFrame largest = iconDecoder.Frames[0]; foreach (BitmapFrame frame in iconDecoder.Frames) { ret.Add(frame); } return(ret); } catch (Exception) { return(ret); } }
private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { if (this.DataContext != null && this.DataContext.GetType() == typeof(DatabaseIndexData)) { DatabaseIndexData index = (DatabaseIndexData)this.DataContext; if (index.Index.TypeId == 0x02393756 && index.Data[0] == 0) //cursor or ico file, there is a riff file which contains a list of icons, hence the check for the first byte { index.Data[2] = 1; //cursor files are ico files except the 3rd byte is 2, not 1. IconBitmapDecoder requires the 3rd byte to be 1. MemoryStream byteStream = new MemoryStream(index.Data); try { IconBitmapDecoder decoder = new IconBitmapDecoder(byteStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); imagePreview.Source = decoder.Frames[0].Thumbnail; txtSize.Text = decoder.Frames.Count.ToString(); } catch { } } else { LoadImage(index.Data); } } }
public Window1() { #region Uninstall Catcher string[] args = Environment.GetCommandLineArgs(); foreach (string arg in args) { if (arg.Split('=')[0].ToLower() == "/u") { string guid = arg.Split('=')[1]; string path = Environment.GetFolderPath(System.Environment.SpecialFolder.System); string str = path + "\\msiexec.exe"; ProcessStartInfo pi = new ProcessStartInfo(str); pi.Arguments = "/i " + guid; pi.UseShellExecute = false; Process.Start(pi); this.Close(); return; } } #endregion InitializeComponent(); IconBitmapDecoder icon = new IconBitmapDecoder(iconUri, BitmapCreateOptions.None, BitmapCacheOption.Default); this.Icon = icon.Frames[0]; this.Closing += new System.ComponentModel.CancelEventHandler(Window1_Closing); this.Loaded += new RoutedEventHandler(Window1_Loaded); }
/// <summary> /// Disassembles an icon and selects the most appropriate image available for the discrete ImageSizes supported by the application. /// </summary> /// <param name="iconSource">The binary source of the icon.</param> /// <returns>A dictionary of suitable images indexed by the ImageSize.</returns> public static Dictionary <ImageSize, ImageSource> DecodeIcon(Byte[] iconSource) { // The return from this operation is a dictionary indexed by the ImageSize. The most appropriate image available is selected for the different image // sizes available. That is, for a small image, it will select the ImageSource that has the given pixel size and the greatest number of colors from // the images stored in the icon. Dictionary <ImageSize, ImageSource> images = new Dictionary <ImageSize, ImageSource>(); // This will extract the various BitmapFrames from the icon and select the best one for the different image sizes. using (MemoryStream memoryStream = new MemoryStream(iconSource)) { // An icon contains several images in various sizes and colors. This will sort the images by the pixel size and select the image with the greatest // color depth. Note for some reason known only to the engineers at Microsoft, the original color depth of the image can only be extracted from // the Thumbnail. They tried to explain why this is so but the reason was illogical and I couldn't repeat it. IconBitmapDecoder iconBitmapDecoder = new IconBitmapDecoder(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); SortedDictionary <Int32, BitmapFrame> availableFrames = new SortedDictionary <Int32, BitmapFrame>(); foreach (BitmapFrame bitmapFrame in iconBitmapDecoder.Frames) { BitmapFrame currentFrame; if (availableFrames.TryGetValue(bitmapFrame.PixelHeight, out currentFrame)) { if (currentFrame.Thumbnail.Format.BitsPerPixel >= bitmapFrame.Thumbnail.Format.BitsPerPixel) { continue; } } availableFrames[bitmapFrame.PixelHeight] = bitmapFrame; } // This will sort the frames into easy-to-use buckets. foreach (KeyValuePair <Int32, BitmapFrame> keyValuePair in availableFrames) { if (keyValuePair.Key <= ImageHelper.smallImageSize) { images[ImageSize.Small] = keyValuePair.Value; } if (keyValuePair.Key <= ImageHelper.mediumImageSize) { images[ImageSize.Medium] = keyValuePair.Value; } if (keyValuePair.Key <= ImageHelper.largeImageSize) { images[ImageSize.Large] = keyValuePair.Value; } if (keyValuePair.Key <= ImageHelper.extraLargeImageSize) { images[ImageSize.ExtraLarge] = keyValuePair.Value; } } } // Freeze the objects for a little performance boost. images[ImageSize.Small].Freeze(); images[ImageSize.Medium].Freeze(); images[ImageSize.Large].Freeze(); images[ImageSize.ExtraLarge].Freeze(); // This is a dictionary of the best images available in the icon indexed by the image size. return(images); }
public static ImageSource GetIcon(Uri uri) { var ibd = new IconBitmapDecoder( uri, BitmapCreateOptions.None, BitmapCacheOption.Default); return(ibd.Frames[0]); }
void OnTextBoxTextChanged(Object sender, TextChangedEventArgs e) { Boolean isSuccessful = false; // This will extract the various BitmapFrames from the icon and select the best one for the different image sizes. try { using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(this.TextBox.Text))) { // An icon contains several images in various sizes and colors. This will sort the images by the pixel size and select the image with the greatest // color depth. Note for some reason known only to the engineers at Microsoft, the original color depth of the image can only be extracted from // the Thumbnail. They tried to explain why this is so but the reason was illogical and I couldn't repeat it. IconBitmapDecoder iconBitmapDecoder = new IconBitmapDecoder(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); SortedDictionary <Int32, BitmapFrame> availableFrames = new SortedDictionary <Int32, BitmapFrame>(); Int32 maxResolution = Int32.MinValue; foreach (BitmapFrame bitmapFrame in iconBitmapDecoder.Frames) { BitmapFrame currentFrame; if (availableFrames.TryGetValue(bitmapFrame.PixelHeight, out currentFrame)) { if (currentFrame.Thumbnail.Format.BitsPerPixel >= bitmapFrame.Thumbnail.Format.BitsPerPixel) { continue; } } availableFrames[bitmapFrame.PixelHeight] = bitmapFrame; maxResolution = Math.Max(maxResolution, bitmapFrame.PixelHeight); } // This will selecte the largest frame for the image. this.Image.Source = availableFrames[maxResolution]; isSuccessful = true; } } catch (NotSupportedException) { } catch (FileFormatException) { } if (!isSuccessful) { try { using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(this.TextBox.Text))) { BitmapDecoder bitmapDecoder = BitmapDecoder.Create(memoryStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); this.Image.Source = bitmapDecoder.Frames[0]; } } catch (NotSupportedException) { } catch (FileFormatException) { } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK); } } }
public static ImageSource GetIcoImageFromSource(string embededlargeImageName) { try { var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(embededlargeImageName); var decorder = new IconBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(decorder.Frames[0]); } catch { return(null); } }
private static void ensureIconsInitialised() { if (iconActive != null) { return; } iconActive = loadIconFromResource("toggl"); iconInactive = loadIconFromResource("toggl_inactive"); }
public MainWindow() { InitializeComponent(); var thisAssembly = Assembly.GetExecutingAssembly(); var stream = thisAssembly.GetManifestResourceStream("BenzGorokuSearch.benz.ico"); var decoder = new IconBitmapDecoder(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.Default); Icon = decoder.Frames[0]; DataContext = new MainWindowViewModel(); }
private static void ConvertIcoToPng(string iconFileName, string pngFileName) { using FileStream IconStream = new FileStream(iconFileName, FileMode.Open, FileAccess.Read); using FileStream PngStream = new FileStream(pngFileName, FileMode.Create, FileAccess.Write); IconBitmapDecoder Decoder = new IconBitmapDecoder(IconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); PngBitmapEncoder Encoder = new PngBitmapEncoder(); Encoder.Frames.Add(Decoder.Frames[0]); Encoder.Save(PngStream); }
public static ImageSource ToImageSource(this Icon icon) { var memoryStream = new MemoryStream(); icon.Save(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); var decoder = new IconBitmapDecoder(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(decoder.Frames[0]); }
public MainWindow() { InitializeComponent(); var thisAssembly = Assembly.GetExecutingAssembly(); var stream = thisAssembly.GetManifestResourceStream("GorokuEdit.benz.ico"); var image = new IconBitmapDecoder(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.Default); Icon = image.Frames[0]; viewModel = new MainWindowViewModel(); DataContext = viewModel; }
private void SetWindowIcon() { try { IconBitmapDecoder ibd = new IconBitmapDecoder( new Uri("pack://application:,,,/" + GetType().Assembly.GetName().Name + ";component/Scutex2.ico", UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.Default); Icon = ibd.Frames[0]; } catch { } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { ImageSource imageSource = null; if (value is IImmagine) { imageSource = ((ImmagineWic)value).bitmapSource as ImageSource; } else if (value is Digiphoto.Lumen.Model.Fotografia) { // Prendo il provino IImmagine immagine = ((Digiphoto.Lumen.Model.Fotografia)value).imgProvino; if (immagine != null) { imageSource = ((ImmagineWic)immagine).bitmapSource as ImageSource; } } else if (value is Digiphoto.Lumen.Eventi.Esito) { // Carico una icona dal file delle risorse Esito esito = (Esito)value; System.IO.Stream stream = null; if (esito == Esito.Ok) { stream = this.GetType().Assembly.GetManifestResourceStream("Digiphoto.Lumen.UI.Resources.information.ico"); } else if (esito == Esito.Errore) { stream = this.GetType().Assembly.GetManifestResourceStream("Digiphoto.Lumen.UI.Resources.error.ico"); } if (stream != null) { //Decode the icon from the stream and set the first frame to the BitmapSource BitmapDecoder decoder = IconBitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.None); imageSource = decoder.Frames [0]; } } else if (value is String) { imageSource = caricaImmagine(value as string); } else { return(value); } return(imageSource); }
private BitmapSource GetIcon() { using (var icon = shortcut.LoadIcon()) { if (icon == null) { return(null); } var ms = new MemoryStream(); icon.Save(ms); var ico = new IconBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(ico.Frames[0]); } }
public static ImageSource GetIcon(string s) { System.Drawing.Icon icon = ManagedWinapi.ExtendedFileInfo.GetIconForFilename(s, false); if (icon == null) { return(null); } using (MemoryStream ms = new MemoryStream()) { icon.Save(ms); var dec = new IconBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); return(dec.Frames[0]); } }
public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value == null) { return(null); } Uri iconFile = new System.Uri(@"pack://application:,,,/" + (string)value, UriKind.Absolute); IconBitmapDecoder dec = new IconBitmapDecoder( iconFile, BitmapCreateOptions.None, BitmapCacheOption.Default); return(dec.Frames[0]); }
public static BitmapFrame GetIcon(string filePath) { try { Icon ico = Icon.FromHandle(GetHandle(filePath)); MemoryStream stream = new MemoryStream(); ico.Save(stream); IconBitmapDecoder ibd = new IconBitmapDecoder(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand); return(ibd.Frames[0]); } catch (Exception ex) { return(null); } }
public MainWindow() { InitializeComponent(); ribbon.DataContext = this; DataContext = this; try { // Apparently this doesn't work in anything but Windows7 IconBitmapDecoder ibd = new IconBitmapDecoder( new Uri(@"pack://*****:*****@"pack://application:,,/Scutex3.ico", UriKind.RelativeOrAbsolute), BitmapCreateOptions.None, BitmapCacheOption.Default); Icon = ibd.Frames[0]; } catch { } } try { Bootstrapper.Configure(); _eventAggregator = ObjectLocator.GetInstance <IEventAggregator>(); _eventAggregator.AddListener <ProductsUpdatedEvent>(x => RefreshData()); _eventAggregator.AddListener <LicenseSavedEvent>(x => SetRecentItemsAndRefresh()); _eventAggregator.AddListener <ServicesUpdatedEvent>(x => RefreshData()); } catch { } Initalize(); SetRecentItems(); VerifyFirstTimeRun(); WelcomeScreenForm welcomeScreenForm = new WelcomeScreenForm(); root.Content = welcomeScreenForm; }