Board index » delphi » DBImage and proportional stretch

DBImage and proportional stretch


2005-09-13 09:36:41 PM
delphi83
Hi,
does anybody know how I can stretch DBImage proportional like Image?
Thanks
Friedhelm Drecktrah, Germany
 
 

Re:DBImage and proportional stretch

didn't it have Stretch property ?
Best Regards
Erick
 

Re:DBImage and proportional stretch

Friedhelm Drecktrah writes:
Quote
Hi,

does anybody know how I can stretch DBImage proportional like Image?

Thanks
Friedhelm Drecktrah, Germany


Not easily, it takes a few lines of code. The following may help,
this code will scale a image to just completely fill (and clip) a panel.
To fill a panel with borders change
if ratioh < ratiow then ratio := ratiow else ratio := ratioh;
to
if ratioh>ratiow then ratio := ratiow else ratio := ratioh;
Procedure Tf_Main.ScaleImage(Image: TImage);
var ratio, ratiow, ratioh: real;
panel: TPanel;
OrgHeight, OrgWidth : integer; //Org == Original
begin
if Image <>nil then
begin
Image.stretch := false;//these 2 lines allow image to return to its
Image.AutoSize := true; // ...original size prior to re-sizing
OrgHeight := image.height;
OrgWidth := image.width;
if (image.width>0 ) and (image.height>0) then
begin
Image.autosize := false;
Image.stretch := true;
ratiow := Panel.width / image.width;
ratioh := Panel.height / image.height;
if ratioh < ratiow then ratio := ratiow else ratio := ratioh;
//scale up to fit
image.width := trunc(OrgWidth * ratio);
image.height := trunc(OrgHeight * ratio);
image.left := trunc((panel.width - image.width)/2);
image.top := trunc((panel.height - image.height)/2);
//these 2 lines center the image in the panel
end
end;
end;