1
votes

in XE5, using TImage, how can I stretch a bitmap with his proportional dimensions? The TImage has 200 pixels width and 300 pixels height. And the bitmap has 130 width and 80 height. When I set Image1.WrapMode to iwStretch the bitmap is resized to fit the TImage's area, but not in the scale proportion of TImage, the bitmap then shows too "fat".

Thanks a lot.

1
Is not TImage.WrapMode = iwFit what you are looking for? It will keep the proportions of the image.LU RD
iwFit is even the default .....David Heffernan
Ok, but when i set it to iwFit the image(bitmap) does not fit the height and width. The size stays the same that iwOriginal. It's a bug?user2880780
Ahh, doc says, that iwFit only can shrink the image (proportionally) if it does not fit. Upscaling is not implemented.LU RD

1 Answers

0
votes

To maintain proportionals you can use the "scale" property. For example, you load an image in img (TImage) on a form and with a button you want to scale it you can do this:

procedure THeaderFooterForm.Button5Click(Sender: TObject);
var testScale : Single;
begin
 img.WrapMode := TImageWrapMode.iwOriginal;
 testScale :=  img.Width / img.Bitmap.Width;
 if (img.Height / img.Bitmap.Height) < testScale then
    testScale := img.Height / img.Bitmap.Height;


 img.Scale.X := testScale;
 img.Scale.Y := testScale;



end;