public static void LoadImageList(string[] extensions) { try { smallIconList.ImageSize = new Size(16, 16); smallIconList.ColorDepth = ColorDepth.Depth32Bit; foreach (string extension in extensions) { if (!FileIcons.SmallIconList.Images.ContainsKey(extension)) { Bitmap smallIcon = IconHandler.IconFromExtension(extension, IconSize.Small); if (smallIcon == null) { smallIcon = Properties.Resources.na_icon; } FileIcons.SmallIconList.Images.Add(extension, smallIcon); } } smallIconList.Images.Add("%line%", Properties.Resources.line_icon); } catch { // DO NOTHING } }
public static void StoreIcon(string extension, string path, string mimeType) { if (!File.Exists(path)) { try { if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } Bitmap image = IconHandler.IconFromExtension(extension, IconSize.Small); System.Drawing.Imaging.Encoder qualityEncoder = System.Drawing.Imaging.Encoder.Quality; long quality = 100; EncoderParameter ratio = new EncoderParameter(qualityEncoder, quality); EncoderParameters codecParams = new EncoderParameters(1); codecParams.Param[0] = ratio; ImageCodecInfo mimeCodecInfo = null; foreach (ImageCodecInfo codecInfo in ImageCodecInfo.GetImageEncoders()) { if (codecInfo.MimeType == mimeType) { mimeCodecInfo = codecInfo; break; } } if (mimeCodecInfo != null) { image.Save(path, mimeCodecInfo, codecParams); // Save to JPG } } catch (Exception ex) { logger.Log <Exception>(LogLevel.Error, "Failed to create icon", ex); } } }