private void SaveImg_btn_Click(object sender, EventArgs e) { using (var SaveFile = new SaveFileDialog()) { if (Functional_Tab.SelectedTab == Convert_Img_Page) { var Extension_selected = ImgExtension.SelectedItem; SaveFile.Filter = $"Image Files(*.{Extension_selected})|*.{Extension_selected.ToString().ToLower()}|All Files(*.*)|*.*"; if (SaveFile.ShowDialog() == DialogResult.OK) { try { switch (Extension_selected) { case "PNG": ImgFormat.ToPng(image_directory, SaveFile.FileName); break; case "ICO": break; case "JPG": ImgFormat.ToJpg(image_directory, SaveFile.FileName); break; case "BMP": ImgFormat.ToBmp(image_directory, SaveFile.FileName); break; case "TIFF": ImgFormat.ToTiff(image_directory, SaveFile.FileName); break; } MessageBox.Show("Изображение успешно сконвертировано", "Успех!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show("Не удалось сохранить изображение", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else if (Functional_Tab.SelectedTab == Edit_Img_Page) { Compress_Image.Compress(image_directory, Compression_ratio_bar.Value); } } }
private void OpenFile_btn_Click(object sender, EventArgs e) { if (Functional_Tab.SelectedTab == Convert_Img_Page) { if (SelectMultipleFiles_radbtn.Checked) { using (var OpenFolder = new FolderBrowserDialog()) { if (OpenFolder.ShowDialog() == DialogResult.OK) { SaveImg_btn.Enabled = true; string images_directory = OpenFolder.SelectedPath; txtPathFile.Text = OpenFolder.SelectedPath; try { if (Directory.Exists(images_directory)) { foreach (string file in Directory.GetFiles(images_directory)) { var Extension_selected = ImgExtension.SelectedItem; switch (Extension_selected) { case "PNG": ImgFormat.ToPng(file, images_directory); break; case "JPG": ImgFormat.ToJpg(file, images_directory); break; case "ICO": //ImgFormat.ToIco(file, images_directory); break; case "BMP": ImgFormat.ToBmp(file, images_directory); break; case "TIFF": ImgFormat.ToTiff(file, images_directory); break; } } //MessageBox.Show("Все файлы успешно сконвертированы", "Успех!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch { MessageBox.Show("Неверный формат файла", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } else if (SelectOneFile_radbtn.Checked) { using (var OpenFolder = new OpenFileDialog()) { OpenFolder.Filter = "Image Files(*.PNG;*.JPG;*.BMP;*.ICO;*.TIFF)|*.PNG;*.JPG;*.BMP;*.ICO;*.TIFF|All files(*.*)|*.*"; if (OpenFolder.ShowDialog() == DialogResult.OK) { SaveImg_btn.Enabled = true; image_directory = OpenFolder.FileName; txtPathFile.Text = image_directory; } } } } else if (Functional_Tab.SelectedTab == Edit_Img_Page) { OpenFile_btn.Enabled = true; using (var OpenFile = new OpenFileDialog()) { OpenFile.Filter = "Image Files(*.JPG)|*.JPG"; if (OpenFile.ShowDialog() == DialogResult.OK) { SaveImg_btn.Enabled = true; image_directory = OpenFile.FileName; Picture = new Bitmap(image_directory); PictureBox.Image = Picture; } } } }