Click here to Skip to main content
11,705,610 members (47,349 online)
Click here to Skip to main content

A Simple Photo Publisher Program

, 20 Nov 2004 38.2K 1.2K 25
Rate this:
Please Sign up or sign in to vote.
This program shows an example of how to manipulate lots of files to convert their size, quality and get a thumbnail image.

Introduction

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);
   
   try
   { 
    this.FullSize=new Bitmap(FullSizePath);
    this.Preview=this.FullSize.GetThumbnailImage(PS.Width,
                               PS.Height,myCallBack,IntPtr.Zero);
    
    this.AllocatedL=true;
    
    
    
   }
   catch
   {
    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);
     LoadingThread.Name="LoadingThread";
     LoadingThread.Start();
  }

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...

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

Share

About the Author

GMachiavelli
Web Developer
Italy Italy
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMissing reference Pin
Marc Clifton21-Nov-04 2:17
protectorMarc Clifton21-Nov-04 2:17 
GeneralRe: Missing reference Pin
GMachiavelli21-Nov-04 3:16
memberGMachiavelli21-Nov-04 3:16 
GeneralRe: Missing reference Pin
Le_MuLoT8-Dec-05 8:33
memberLe_MuLoT8-Dec-05 8:33 
AnswerRe: Missing reference Pin
z00z07-Jun-08 0:57
memberz00z07-Jun-08 0:57 

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 | Terms of Use | Mobile
Web03 | 2.8.150819.1 | Last Updated 20 Nov 2004
Article Copyright 2004 by GMachiavelli
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid