Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

C# Batch Photo Resize

0.00/5 (No votes)
18 Feb 2008 1  
One small example teaching how to create a software for resizing and editing pictures

Introduction

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.

photo_resize.JPG

Background

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) 
{ 
    imgPhoto.SetPropertyItem(e); 
}

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.

History

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

Thanks

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here