Click here to Skip to main content
Click here to Skip to main content

C# Batch Photo Resize

, 18 Feb 2008
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Renan Rodrigues Duarte
Software Developer
Brazil Brazil
Check my Resumé at www.renanrodriguesduarte.org

Comments and Discussions

 
Questionphotoshop alternative can do that too Pinmembersugar213428-May-13 23:33 
QuestionSimple solution is here - http://aspnethelper.com/tutorial/10 Pinmemberarijit0072-Apr-12 0:53 
GeneralMy vote of 5 Pinmemberjackjiazhiqiang6-Jul-11 19:43 
GeneralThank You very much Renan PinmemberPaul Chu31-Aug-10 15:36 
GeneralMy vote of 5 PinmemberRodrigo Coimbra3-Aug-10 7:04 
Generalresize photo Pinmemberantony0929-Dec-09 23:52 
GeneralThank you so much for your code. It really helped me. Pinmembersangram_ctp25-Nov-09 23:41 
GeneralThis is what I demand. PinmemberRin Reaksmey11-Sep-08 17:13 
Generalnice one. PinmemberGautam Sharma2-Jul-08 17:39 
QuestionWhy RotateFlip ? Pinmembertaichitof3-Jun-08 21:25 
AnswerRe: Why RotateFlip ? PinmemberPGumbo10-Dec-08 9:25 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 18 Feb 2008
Article Copyright 2008 by Renan Rodrigues Duarte
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid