/// <summary> /// Gets the icon entry with the specified width and height. /// </summary> /// <param name="size">Width and height of the entry to get.</param> /// <param name="bestSupported">The "best" entry type allowed to get. /// Use Compressed to get all entries; TrueColor to get all except /// the Vista-only compressed entries; and Classic to get only the /// classic icons that run on all Windows versions. /// </param> /// <returns>Gets the entry matching the size. If multiple supported /// entries are available, the only with the highest color depth is returned. /// If no matching entry is found, null is returned.</returns> public IconEntry GetEntry(Size size, IconEntryType bestSupported) { IconEntry best = null; foreach (IconEntry e in this.Icons) { if (e.Size == size && e.Type <= bestSupported) { if (best == null || best.ColorDepth < e.ColorDepth) { best = e; } } } return(best); }
void ReplaceWithImageToolStripMenuItemClick(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "Images|*.png;*.bmp;*.gif;*.jpg|All files|*.*"; if (dlg.ShowDialog() == DialogResult.OK) { Bitmap newBitmap = new Bitmap(dlg.FileName); // scale to correct size and make it ARGB string oldFormat = entry.Width + "x" + entry.Height + "x" + entry.ColorDepth; string newFormat = newBitmap.Width + "x" + newBitmap.Height + "x"; if (newBitmap.Width != entry.Width || newBitmap.Height != entry.Height) { MessageBox.Show("The loaded bitmap has the"); } //entry.SetTrueColorImage(newBitmap, entry.IsCompressed); newBitmap.Dispose(); this.Entry = entry; // re-display bitmap } } }
void LoadIcon(Stream stream) { BinaryReader r = new BinaryReader(stream); if (r.ReadUInt16() != 0) { throw new InvalidIconException("reserved word must be 0"); } ushort type = r.ReadUInt16(); if (type == 1) { isCursor = false; } else if (type == 2) { isCursor = true; } else { throw new InvalidIconException("invalid icon type " + type); } if (isCursor) { throw new InvalidIconException("cursors are currently not supported"); } IconEntry[] icons = new IconEntry[r.ReadUInt16()]; for (int i = 0; i < icons.Length; i++) { icons[i] = new IconEntry(); icons[i].ReadHeader(r, ref wellFormed); } for (int i = 0; i < icons.Length; i++) { icons[i].ReadData(stream, ref wellFormed); } this.icons = new Collection <IconEntry>(icons); }
void LoadIcon(Stream stream) { BinaryReader r = new BinaryReader(stream); if (r.ReadUInt16() != 0) throw new InvalidIconException("reserved word must be 0"); ushort type = r.ReadUInt16(); if (type == 1) isCursor = false; else if (type == 2) isCursor = true; else throw new InvalidIconException("invalid icon type " + type); if (isCursor) throw new InvalidIconException("cursors are currently not supported"); IconEntry[] icons = new IconEntry[r.ReadUInt16()]; for (int i = 0; i < icons.Length; i++) { icons[i] = new IconEntry(); icons[i].ReadHeader(r, ref wellFormed); } for (int i = 0; i < icons.Length; i++) { icons[i].ReadData(stream, ref wellFormed); } this.icons = new Collection<IconEntry>(icons); }