C++ C++ C# C# ASP.NET Security ASP.NET Security ASM ASM Скачать Скачать Поиск Поиск Хостинг Хостинг  
  Программа для работы с LPT портом...
Язык: .NET — ©Alexey...
  "ASP.NET Atlas" – AJAX в исполнении Micro...
Язык: .NET — ©legigor@mail.ru...
  "Невытесняющая" Многопоточность...
Язык: C/C++ — ©...
  Update World C++: Сборник GPL QT исходников
  Весь сайт целиком можно загрузить по ссылкам из раздела Скачать
Дебетовая карта Home Credit [CPS] RU

 A Simple Photo Publisher Program / Graphics / C#


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

Дебетовая карта Home Credit [CPS] RU