using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Drawing.Imaging; //Required for Image Format namespace Simple_Image_Resizer { public partial class MainForm : Form { public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); } void BrowseClick(object sender, EventArgs e) //Browsw button click method { if(DialogResult.Cancel != openFileDialog1.ShowDialog()) //Show Open Dialog box and display path in Browsetext textbox { Browsetext.Text = openFileDialog1.FileName; } } void DestinationClick(object sender, EventArgs e) //Destination button click method { if (DialogResult.Cancel != saveFileDialog1.ShowDialog()) // Show Save Dialog box and display path in Destinationtext textbox { Destinationtext.Text = saveFileDialog1.FileName; } } void GoClick(object sender, EventArgs e) //method for go button click { try { if(PercentButton.Checked == true) //If the percent radio button is checked do this { decimal percent = numericUpDown1.Value/100; //Get percentage from user and devide by 100 and store in percent Bitmap theImage = new Bitmap(Browsetext.Text); //Get original image and store it as theImage int height = theImage.Size.Height; //Get the size of the original image and store in an int varible int width = theImage.Size.Width; int newheight = Convert.ToInt32 (height*percent); //Calculate new height and store in newheight int newwidth = Convert.ToInt32 (width*percent); //Calculate new width and store in newwidth if(MessageBox.Show("This will resize this image to " + newheight + " pixels/high and " + newwidth + " pixels/wide - Do You Want to Contunue?", "Simple Image Resizer",MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK ) //Message box to confirm image resize Ok/cancel { Bitmap result = new Bitmap(newwidth,newheight); //Create a new image with the new dimensions Graphics g = Graphics.FromImage(result); g.DrawImage(theImage, 0, 0, newwidth, newheight); result.Save(Destinationtext.Text, ImageFormat.Jpeg); //Save file in the destination as a Jpeg MessageBox.Show("Successfully resized the image!"); // Messagebox to confirm success } } if(CustomSize.Checked == true){ //If the percent radio button is checked do this Bitmap theImage = new Bitmap(Browsetext.Text); //Get original image and store it as theImage int cheight = Convert.ToInt32 (customheight.Text); // Get custom height from textbox int cwidth = Convert.ToInt32 (customwidth.Text); // Get custom width from textbox if(MessageBox.Show("This will resize this image to " + cheight + " pixels/high and " + cwidth + " pixels/wide - Do You Want to Contunue?", "Simple Image Resizer",MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK ) //Message box to confirm image resize Ok/cancel { Bitmap result = new Bitmap(cwidth,cheight); //Make a new image called result with customwidth and customheight Graphics g = Graphics.FromImage(result); g.DrawImage(theImage, 0, 0, cwidth, cheight); result.Save(Destinationtext.Text, ImageFormat.Jpeg); //Save file in the destination as a Jpeg MessageBox.Show("Successfully resized the image!"); // Messagebox to confirm success } } } catch // Catch to make sure form is filled correclty { MessageBox.Show("Please fill each required field correclty."); } } } }