Главная страница | назад

Article #20164: Creating Thumbnails for Images Using TImage

QUESTION: I'm trying to create a thumbnail of a .jpg image on my form for a viewer program. Is there a quick way to accomplish this?

ANSWER: You can use TCanvas::StretchDraw().

This sample uses two TImage components, an OpenPictureDialog, and a TButton.

Drop the two TImage components on the form and name the first imgMain and set its dimensions to 400x400(Height x Width). Name the second TImage imgThumb and set its dimensions to 100x100. Then drop a TButton and the OpenPictureDialog component on the form and name them btnOpen and OpenPictureDialog respectively.

Define btnOpen OnCLick event:

void __fastcall TForm1::btnOpenClick(TObject *Sender)
  OpenPictureDialog->Filter = "JPEG Image File (*.jpg)|*.jpg";
            TJPEGImage *jpg = new TJPEGImage();
            ShowMessage("Unable to load: " + OpenPictureDialog->FileName);
    delete jpg;

Last Modified: 10-MAY-00