/// <summary> /// Extracts an icon from a givin icon file or an executable module (.dll or an .exe file). /// </summary> /// <param name="fileName">The path of the icon file or the executable module.</param> /// <param name="iconIndex">The index of the icon in the executable module.</param> /// <returns>A System.Drawing.Icon extracted from the file at the specified index in case of an executable module.</returns> public static Icon ExtractIcon(string fileName, int iconIndex) { //Try to load the file as icon file. if (System.IO.Path.GetExtension(fileName).Equals(".ico", StringComparison.InvariantCultureIgnoreCase)) { return(new Icon(fileName)); } //Load the file as an executable module. using (IconExtractor extractor = new IconExtractor(fileName)) { return(extractor.GetIconAt(iconIndex)); } }
/// <summary> /// Extracts all the icons from a givin icon file or an executable module (.dll or an .exe file). /// </summary> /// <param name="fileName">The path of the icon file or the executable module.</param> /// <returns> /// A list of System.Drawing.Icon found in the file. /// If the file was an icon file, it will return a list containing a single icon. /// </returns> public static List <Icon> ExtractAllIcons(string fileName) { List <Icon> list = new List <Icon>(); //Try to load the file as icon file. if (System.IO.Path.GetExtension(fileName).Equals(".ico", StringComparison.InvariantCultureIgnoreCase)) { list.Add(new Icon(fileName)); return(list); } //Load the file as an executable module. using (IconExtractor extractor = new IconExtractor(fileName)) { for (int i = 0; i < extractor.IconCount; i++) { list.Add(extractor.GetIconAt(i)); } } return(list); }