public static Bitmap GetIconImage(string file, int index) { Icon icon; try { if (Path.GetExtension(file).ToLower() == ".ico") { icon = new Icon(file); } else { icon = IconFormator.LoadIcon(file)[index]; } } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } return(IconFormator.SplitIcon(icon).Last().ToBitmap()); }
private void BtnSaveIco_Click(object sender, EventArgs e) { if (!PrepareIcons(imgIco)) { MessageBox.Show("No size of Icon is selected"); return; } var dlg = new SaveFileDialog() { Filter = "Icon Files (*.ico)|*.ico|Portable Network Graphic (*.png)|*.png|WebP Format (*.webp)|*.webp" }; if (dlg.ShowDialog() == DialogResult.OK) { string file = Path.GetFileNameWithoutExtension(dlg.FileName); string dir = Path.GetDirectoryName(dlg.FileName); switch (dlg.FilterIndex) { case 1: IconFormator.SaveIcon(imgIcos, dlg.FileName); break; case 2: foreach (var img in imgIcos) { img.Save($"{Path.Combine(dir, file)}@{img.Width}_{img.Height}.png", ImageFormat.Png); } break; case 3: foreach (var img in imgIcos) { WebpFormator.ImageToWebp(img, $"{Path.Combine(dir, file)}@{img.Width}_{img.Height}.webp"); } break; } } }