Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can anyone help me simplify this Resizing code

Status
Not open for further replies.
Jul 14, 2003
4
US
Can you simplify this code? I know it is possible and I think there are some commands that are useable that I don´t know about so please help.
This code is ment to resize an image so it fits in a window with some controls (that's what the minus numbers are for)


procedure TFrm_Main.Hlutfallsreikningur ;
var
Ratio : double;
begin
Ratio:=(image1.Picture.height) / (image1.picture.width) ; //Calcs the ratio beetween height and width

if Frm_Main.height > Frm_Main.width then // Experimetal code
begin
image1.height:=Frm_Main.Height -100 ;
image1.width:=trunc(image1.height / Ratio);
if image1.width > Frm_Main.width -190 then
begin
image1.width:=Frm_Main.width -190 ;
image1.height:=trunc(image1.width * Ratio);
end;
end;
if Frm_Main.height <= Frm_Main.width then
begin
image1.width:=Frm_Main.width -190 ;
image1.height:=trunc(image1.width * Ratio);
if image1.height > Frm_Main.height - 100 then
begin
image1.height:=Frm_Main.height -100 ;
image1.width:=trunc(image1.height / Ratio);
end;
end;
end;
 
TImage has a couple of properties that might help you.
Stretch: stretches the image to fit the size of the image control on the form. It resizes the image to the height and width of the image control.

AutoSize: this one resizes the control, to accomodate the entire image. it adjusts the width and height properties of the image control, making them big enough to fit the image.

Now if you set AutoSize to False, and Stretch to True it will automatically resize the image to the width and height of the image control.

Hope this helps
 
Oh, and if what you want is to resize the actuall image control depending on the size of the Form it's in you can use the Align property. it depending on the value it can align it to the height of the form on the left or right sides of the form, to the width at the top or bottom of the form, or to the form's dimensions. covering the enitre form.
 
Thank you but I already know about that the prolem is ,what i forgot to say before is to hold the aspect ratio for the image so it when I would resize the form the image would go with it and holding the aspect ratio of the image.
 
Thank you but I already know about that the prolem is ,what i forgot to say before is to hold the aspect ratio for the image so it when I would resize the form the image would go with it and holding the aspect ratio of the image.
 
Thank you but I already know about that the prolem is ,what i forgot to say before is to hold the aspect ratio for the image so it when I would resize the form the image would go with it and holding the aspect ratio of the image.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top