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; } } }
public static Bitmap GetPictureImage(string file) { string ext = Path.GetExtension(file).ToLower(); Bitmap img = null; switch (ext) { case ".jpg": case ".png": case ".bmp": img = new Bitmap(file); break; case ".svg": img = SvgFormator.SvgToImage(file); break; case ".webp": img = WebpFormator.WebpToImage(file); break; } return(img); }