Click here to Skip to main content
15,559,568 members
Articles / Multimedia / GDI+
Posted 17 Feb 2008


68 bookmarked

C# Batch Photo Resize

Rate me:
Please Sign up or sign in to vote.
4.13/5 (12 votes)
18 Feb 2008CPOL3 min read
One small example teaching how to create a software for resizing and editing pictures


In this article, I will try to provide some help in creating a photo resize software using C# and its basic namespaces. The software itself will try to fit all types and sizes of images to a ‘web’ version giving the user the option to choose the folder, destination path and also the option to insert subtitles and a transparent banner. By default, the .NET Framework is essential.



This software requires attention to multi-language support: we declare variables for all the labels and buttons titles as public strings and we change their container when the user changes the software's language. To resize the pictures, I got information from MSDN forums and C# documentation; using System.Drawing it's possible to create 'big thumbnails' from the raw images without losing the original resolution. To insert the subtitles and manage the transparent banners on the pictures, I used as my source the article Creating a Watermarked Photograph with GDI+ for .NET. The transparent banner will be inserted setting two color manipulations. On the first, we remove the back color with one that is transparent and then we change the opacity of this by applying a 5x5 matrix that contains the coordinates for the RGBA space. The pictures will be resized using a scale scanning which means that different scales need different sizes (pictures can be 640x480 or 480x640).

Using the Code

Is the file a valid picture-file? What is the main scale to use? Starting with the ReziseImage() that basically checks the size, container and scale, we set the new size and throw a ‘new-picture-size’ to the memory. We will use this new image ‘variable’ to add the banner or text (if the user wants).

This function will also call at its end the InsertBannerAndText() that will manage the image attributes to add or not to add the banner and text to the bottom of the file. We'll also check the size of the picture to know which font-size we will use. A good thing to pay attention to is that when we treat these images with Image objects, we also have to copy the camera details manually. This means that, if you don't want to lose the EXIF data, you need to use the above code to save all the picture information files like camera type, picture date, camera functions used, etc.

foreach (PropertyItem e in imagem.PropertyItems) 

For more information, read this.

The function Draw() will create the image to show on the Windows forms. It also does the scale check and generation of the picture. Then, throw it on the Picture Box on the main form. At the end of the code, we have buttons that search for pictures in specified folders and skip pictures that we don't want to resize.

Points of Interest

The point of interest of this software is to try to make the job of resizing pictures easier every time before we send pictures to services like Orkut, Facebook, Picasa, etc. facing problems with the big size files or slow connections of cyber cafés that cannot manage anymore the new camera types with their huge picture quality.


  • 1.7.1 – Web Release (24-October-2007)


Thanks Matthis Kiechle for the German translation, software tests and bugs searches.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer
Brazil Brazil
Check my Resumé at

Comments and Discussions

Questionphotoshop alternative can do that too Pin
sugar213429-May-13 0:33
sugar213429-May-13 0:33 
QuestionSimple solution is here - Pin
arijit0072-Apr-12 1:53
arijit0072-Apr-12 1:53 
GeneralMy vote of 5 Pin
jackjiazhiqiang6-Jul-11 20:43
jackjiazhiqiang6-Jul-11 20:43 
GeneralThank You very much Renan Pin
Paul Chu31-Aug-10 16:36
Paul Chu31-Aug-10 16:36 
GeneralMy vote of 5 Pin
Rodrigo Coimbra3-Aug-10 8:04
Rodrigo Coimbra3-Aug-10 8:04 
Generalresize photo Pin
antony0930-Dec-09 0:52
antony0930-Dec-09 0:52 
GeneralThank you so much for your code. It really helped me. Pin
sangram_ctp26-Nov-09 0:41
sangram_ctp26-Nov-09 0:41 
GeneralThis is what I demand. Pin
Reaksmey Rin11-Sep-08 18:13
Reaksmey Rin11-Sep-08 18:13 
Generalnice one. Pin
Gautam Sharma2-Jul-08 18:39
Gautam Sharma2-Jul-08 18:39 
Good one but this can also be done with the free tool, like one google has, like picasa.

But a good artical.

Happy coding

QuestionWhy RotateFlip ? Pin
taichitof3-Jun-08 22:25
taichitof3-Jun-08 22:25 
AnswerRe: Why RotateFlip ? Pin
PGumbo10-Dec-08 10:25
PGumbo10-Dec-08 10:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.