public Icon (Icon original, Size size) { if (original == null) throw new ArgumentException ("original"); iconSize = size; iconDir = original.iconDir; int count = iconDir.idCount; if (count > 0) { imageData = original.imageData; id = UInt16.MaxValue; for (ushort i=0; i < count; i++) { IconDirEntry ide = iconDir.idEntries [i]; if ((ide.height == size.Height) || (ide.width == size.Width)) { id = i; break; } } // if a perfect match isn't found we look for the biggest icon *smaller* than specified if (id == UInt16.MaxValue) { int requested = Math.Min (size.Height, size.Width); IconDirEntry best = iconDir.idEntries [0]; for (ushort i=1; i < count; i++) { IconDirEntry ide = iconDir.idEntries [i]; if ((ide.height < requested) || (ide.width < requested)) { if ((ide.height > best.height) || (ide.width > best.width)) id = i; } } } // last one, if nothing better can be found if (id == UInt16.MaxValue) id = (ushort) (count - 1); iconSize.Height = iconDir.idEntries [id].height; iconSize.Width = iconDir.idEntries [id].width; } else { iconSize.Height = size.Height; iconSize.Width = size.Width; } if (original.bitmap != null) bitmap = (Bitmap) original.bitmap.Clone (); }
public Icon (Icon original, Size size) { if (original == null) throw new ArgumentException ("original"); iconSize = size; iconDir = original.iconDir; int count = iconDir.idCount; if (count > 0) { imageData = original.imageData; id = UInt16.MaxValue; for (ushort i=0; i < count; i++) { IconDirEntry ide = iconDir.idEntries [i]; if (((ide.height == size.Height) || (ide.width == size.Width)) && !ide.ignore) { id = i; break; } } // if a perfect match isn't found we look for the biggest icon *smaller* than specified if (id == UInt16.MaxValue) { int requested = Math.Min (size.Height, size.Width); // previously best set to 1st image, as this might not be smallest changed loop to check all IconDirEntry? best = null; for (ushort i=0; i < count; i++) { IconDirEntry ide = iconDir.idEntries [i]; if (((ide.height < requested) || (ide.width < requested)) && !ide.ignore) { if (best == null) { best = ide; id = i; } else if ((ide.height > best.Value.height) || (ide.width > best.Value.width)) { best = ide; id = i; } } } } // last one, if nothing better can be found if (id == UInt16.MaxValue) { int i = count; while (id == UInt16.MaxValue && i > 0) { i--; if (!iconDir.idEntries [i].ignore) id = (ushort) i; } } if (id == UInt16.MaxValue) throw new ArgumentException ("Icon", "No valid icon image found"); iconSize.Height = iconDir.idEntries [id].height; iconSize.Width = iconDir.idEntries [id].width; } else { iconSize.Height = size.Height; iconSize.Width = size.Width; } if (original.bitmap != null) bitmap = (Bitmap) original.bitmap.Clone (); }
public Icon(Icon original, Size size) { if (original == null) { throw new ArgumentNullException(nameof(original)); } iconSize = size; iconDir = original.iconDir; int count = iconDir.idCount; if (count > 0) { imageData = original.imageData; id = ushort.MaxValue; for (ushort i = 0; i < count; i++) { IconDirEntry ide = iconDir.idEntries[i]; if (((ide.height == size.Height) || (ide.width == size.Width)) && !ide.png) { id = i; break; } } // if a perfect match isn't found we look for the biggest icon *smaller* than specified if (id == ushort.MaxValue) { int requested = Math.Min(size.Height, size.Width); // previously best set to 1st image, as this might not be smallest changed loop to check all IconDirEntry?best = null; for (ushort i = 0; i < count; i++) { IconDirEntry ide = iconDir.idEntries[i]; if (((ide.height < requested) || (ide.width < requested)) && !ide.png) { if (best == null) { best = ide; id = i; } else if ((ide.height > best.Value.height) || (ide.width > best.Value.width)) { best = ide; id = i; } } } } // last one, if nothing better can be found if (id == ushort.MaxValue) { int i = count; while (id == ushort.MaxValue && i > 0) { i--; if (!iconDir.idEntries[i].png) { id = (ushort)i; } } } if (id == ushort.MaxValue) { throw new ArgumentException(SR.NoValidIconImageFound, nameof(original)); } iconSize.Height = iconDir.idEntries[id].height; iconSize.Width = iconDir.idEntries[id].width; } else { iconSize.Height = size.Height; iconSize.Width = size.Width; } if (original.bitmap != null) { bitmap = (Bitmap)original.bitmap.Clone(); } }
public Icon(Icon original, Size size) { if (original == null) { throw new ArgumentException("original"); } iconSize = size; iconDir = original.iconDir; int count = iconDir.idCount; if (count > 0) { imageData = original.imageData; id = UInt16.MaxValue; for (ushort i = 0; i < count; i++) { IconDirEntry ide = iconDir.idEntries [i]; if ((ide.height == size.Height) || (ide.width == size.Width)) { id = i; break; } } // if a perfect match isn't found we look for the biggest icon *smaller* than specified if (id == UInt16.MaxValue) { int requested = Math.Min(size.Height, size.Width); IconDirEntry best = iconDir.idEntries [0]; for (ushort i = 1; i < count; i++) { IconDirEntry ide = iconDir.idEntries [i]; if ((ide.height < requested) || (ide.width < requested)) { if ((ide.height > best.height) || (ide.width > best.width)) { id = i; } } } } // last one, if nothing better can be found if (id == UInt16.MaxValue) { id = (ushort)(count - 1); } iconSize.Height = iconDir.idEntries [id].height; iconSize.Width = iconDir.idEntries [id].width; } else { iconSize.Height = size.Height; iconSize.Width = size.Width; } if (original.bitmap != null) { bitmap = (Bitmap)original.bitmap.Clone(); } }
public Icon (Icon original, Size size) { this.iconSize = size; this.winHandle = original.winHandle; this.iconDir = original.iconDir; this.imageData = original.imageData; int count = iconDir.idCount; bool sizeObtained = false; for (int i=0; i<count; i++){ IconDirEntry ide = iconDir.idEntries [i]; if (!sizeObtained) if (ide.height==size.Height && ide.width==size.Width) { this.id = (ushort) i; sizeObtained = true; this.iconSize.Height = ide.height; this.iconSize.Width = ide.width; break; } } if (!sizeObtained){ uint largestSize = 0; for (int j=0; j<count; j++){ if (iconDir.idEntries [j].bytesInRes >= largestSize){ largestSize = iconDir.idEntries [j].bytesInRes; this.id = (ushort) j; this.iconSize.Height = iconDir.idEntries [j].height; this.iconSize.Width = iconDir.idEntries [j].width; } } } }