The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
When I downloaded my pictures from my digital camera I found that they were very large and I had to spend a long time to upload them and to resize them individually. So I wrote this simple application that resizes all the images in a specified folder.
Using the code
The code is very simple. As you can see in the form, it is very simple and understandable. First you choose the folder and then click Start to begin the resizing process and you can change the resizing factor and the folder name that will contain the resized images.
The code uses the
System.Drawing.Imaging namespaces. The first one is used to create folders and the second one used to specify the image format.
The first button will open the
FolderBrowserDialog which allows you to choose the folder that contains the images to be resized.
private void button1_Click(object sender, System.EventArgs e)
DialogResult dr = folderBrowserDialog1.ShowDialog();
if(dr == DialogResult.OK)
path = folderBrowserDialog1.SelectedPath;
After we choose the folder we click on the second button to start resizing and here is the code:
private void button2_Click(object sender, System.EventArgs e)
DirectoryInfo newDiroctory = new DirectoryInfo(path+"\\"+textBox3.Text);
string newPath =path +"\\"+ textBox3.Text+"\\";
string images = Directory.GetFiles(path);
int couter = 0; for (int i=0;i < images.Length;i++)
string fileExtention =
images[i].Substring(images[i].Length - 3, 3);
Image currentImage = Image.FromFile(images[i]);
int h = currentImage.Height;
int w = currentImage.Width;
float factor =
int newH = (int)Math.Ceiling((double)h*factor);
int newW = (int)Math.Ceiling((double)w*factor);
string imageName = images[i].Substring(path.Length+1,
Bitmap newBitmap = new Bitmap(currentImage,new Size(newW,newH));
" images was resized and its path is:"+newPath,"Done");
The code is very simple and there is a lot of helpful comments.