Click here to Skip to main content
15,174,850 members
Articles / Desktop Programming / Windows Forms
Posted 20 Nov 2004


25 bookmarked

A Simple Photo Publisher Program

Rate me:
Please Sign up or sign in to vote.
2.42/5 (6 votes)
20 Nov 20042 min read
This program shows an example of how to manipulate lots of files to convert their size, quality and get a thumbnail image.


A Picture Publisher converts size, names, compresses pictures (.bmp, .gif, .jpg) and generates preview images (like web albums). Simple use of threads is shown here. You can find the updates in Guidomarche.NET. This is a very simple program used for converting many graphics files at the same time. SinglePhoto.cs contains a class that is used to gather information about each photo to process, such as the original path, size, compression, the new path, size and compression. It only stores information about the new picture properties. New pictures are created only when they are saved.

private int quality;
private string FullSizePath;
private string PreviewPathOut;
private string FullSizePathOut;
private bool AllocatedL;
private System.Drawing.Size FS; //full size
private System.Drawing.Size PS; //preview

When the associated image needs to be processed or shown, the image is allocated in memory with the following code:

public bool Allocate()
   System.Drawing.Image.GetThumbnailImageAbort myCallBack = 
    new System.Drawing.Image.GetThumbnailImageAbort(PreviewFail);
    this.FullSize=new Bitmap(FullSizePath);
    return false;
   return true;

Now the SinglePhoto object contains a full size image (the original) and a preview image. myCallBack is something like a delegate, which is required to handle failures in GetThumbnailImage method. Using SinglePhoto's FHeight, FWidth, PHeight, PWidth or FSSize ,PSSize proprieties, or using ResizeFS(int alt, int larg), ResizePS(int alt, int larg) you can set the size of the picture, and get a resized picture using FsImg, PrvImg properties.

The automated task zone, contains a few ways of generating a sequence of names for photos. I would like to add a few words on StartLoad() and StartSave(): I decided to load and save pictures in a separate thread, to avoid "freezing" of the graphic interface. A good idea is to convert and save each picture using a different thread, in order to speed up the operations. But I am not sure whether it will be really faster. Running a thread is very simple, this shows how to run a thread:

private void StartLoad()
     ThreadStart LoadingThreadDelegate=new ThreadStart(this.LoadTasks);
     Thread LoadingThread= new Thread(LoadingThreadDelegate);

All you have to do is, create a ThreadStart object, linked to the method you want to start with, when the thread starts. In this example, I have created LoadingThreadDelegate=new ThreadStart(this.LoadTasks), a ThreadStart object linked to this.LoadTasks(). Then you can use the ThreadStart object (named LoadingThreadDelegate) to create a new Thread object, and then start it. After LoadingThread.Start() is executed, the method LoadTasks() and the main thread (user interface) will run concurrently.

That's all...


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


About the Author

Web Developer
Italy Italy
No Biography provided

Comments and Discussions

GeneralMissing reference Pin
Marc Clifton21-Nov-04 3:17
mvaMarc Clifton21-Nov-04 3:17 
GeneralRe: Missing reference Pin
GMachiavelli21-Nov-04 4:16
MemberGMachiavelli21-Nov-04 4:16 
GeneralRe: Missing reference Pin
Le_MuLoT8-Dec-05 9:33
MemberLe_MuLoT8-Dec-05 9:33 
AnswerRe: Missing reference Pin
z00z07-Jun-08 1:57
Memberz00z07-Jun-08 1:57 

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.