Board index » delphi » How to create thumbnail image with Delphi 4?

How to create thumbnail image with Delphi 4?

Quote
>After I load the image to TPicture, is there any method that I can resize
>the picture and save it?

There isn't a built-in method (unless they added it in D4), but you can
write one pretty easily.

This is from memory... but it should work:

procedure saveThumbnail(fileName: string; myPicture:TPicture; thumbWidth,
thumbHeight : integer);
var
    myBMP : TBitmap;
begin
        myBMP := TBitmap.create;
    with myBMP do begin
        width := thumbWidth;
        height:= thumbHeight;
        palette := (myPicture.bitmap.palette);
        canvas.CopyRect(rect(0,0,width,height), myPicture.bitmap.canvas,
                                        myPicture.bitmap.canvas.clipRect);
        saveToFile(fileName);
    end;
    myBMP.free;
end;

 

Re:How to create thumbnail image with Delphi 4?


After I load the image to TPicture, is there any method that I can resize
the picture and save it?

Thanks in advance

Calvin Sung

Re:How to create thumbnail image with Delphi 4?


Quote
Calvin wrote in message <7d95ql$ch...@eng-ser1.erg.cuhk.edu.hk>...
>After I load the image to TPicture, is there any method that I can resize
>the picture and save it?

>Thanks in advance

>Calvin Sung

Hi Calvin.

You can do this using the StretchDraw method of TCanvas.  Try this code:

{ Assume that Image1 is an image on the form which contains the picture you
want to stretch }
{ This example stretches the picture to 100x200 }

procedure TForm1.Button1Click(Sender: TObject);
var
  BM: TBitmap;
begin
  BM := TBitmap.Create;
  try
    BM.Width := 100;
    BM.Height := 200;
    BM.Canvas.StretchDraw(Rect(0, 0, 99, 199), Image1.Picture.Graphic);
    BM.SaveToFile('c:\stretched bitmap.bmp');
  finally
    BM.Free;
  end;
end;

HTH,

Cameron
_______________________
cameronm...@hotmail.com

Other Threads