private void button2_Click(object sender, EventArgs e) { string message = null; try { if (radioButton1.Checked) { textBox2.Text = fbd.SelectedPath + "\\converted-image" + "." + ConvertType.Jpg; imager.Convert(textBox1.Text, textBox2.Text, ConvertType.Jpg); message = "Converted to jpg"; MessageBox.Show(message); } if (radioButton2.Checked) { textBox2.Text = fbd.SelectedPath + "\\converted-image" + "." + ConvertType.Png; imager.Convert(textBox1.Text, textBox2.Text, ConvertType.Png); message = "Converted to png"; MessageBox.Show(message); } if (radioButton3.Checked) { textBox2.Text = fbd.SelectedPath + "\\converted-image" + "." + ConvertType.Gif; imager.Convert(textBox1.Text, textBox2.Text, ConvertType.Gif); message = "Converted to gif"; MessageBox.Show(message); } } catch (IfImageNullOrEmptyException) { message = "Please Select Existing Image"; MessageBox.Show(message); } catch (IfImageAlreadyExistsException) { message = "The Image Already Exists"; MessageBox.Show(message); } catch (IfImageNotFoundException) { message = "Image Not Found"; MessageBox.Show(message); } catch (InvalidImageException) { message = "Invalid Image"; MessageBox.Show(message); } }
public ActionResult ToJpg(int id) { Image imageModel = new Image(); Imager imager = new Imager(); using (DbModelsss db = new DbModelsss()) { imageModel = db.Images.Where(x => x.ImageId == id).FirstOrDefault(); } string fileName = Path.GetFileName(imageModel.ImagePath); imageModel.ImagePath = "~/Image/" + fileName; fileName = Path.Combine(Server.MapPath("~/Image/"), fileName); string destName = Path.GetFileNameWithoutExtension(imageModel.ImagePath); destName = Path.Combine(Server.MapPath("~/Image/ToJpg/"), destName); destName += ".jpg"; try { imager.Convert(fileName, destName, ConvertType.Jpg); } catch (Exception ex) { return View("Error", ex); } return RedirectToAction("View/0"); }
private void ConvertButton_Click(object sender, RoutedEventArgs e) { string message = null; try { Imager imager = new Imager(); string destinationPath = System.IO.Path.Combine(model.DestinationPath, model.FileName + "." + model.ConvertType.ToString().ToLower()); imager.Convert(model.SourcePath, destinationPath, model.ConvertType); message = "The image was successfully converted!"; } catch (ImageNotFoundException) { message = "Please select an existing image!"; } catch (ImageNullOrEmptyException) { message = "Please choose a source image!"; } catch (ImageAlreadyExistsException) { message = "Image with this name already exists! Please change the destination path."; } catch (InvalidImageException) { message = "Invalid image format!"; } finally { MainWindow.Instance.ShowMessage(message); } }
private void Convert() { Console.Clear(); Console.Write("Available formats: JPG,GIF,PNG\n\n"); Console.Write("SourceDestination: "); string sourcePath = Console.ReadLine(); Console.Write("DestinationPath: "); string destinatonPath = Console.ReadLine(); Console.Write("Format: "); string imageFormat = Console.ReadLine(); imager.Convert(sourcePath, destinatonPath, (ConvertType)Enum.Parse(typeof(ConvertType), imageFormat, true)); }