1

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.

LU RD
  • 34,438
  • 5
  • 88
  • 296
user2880780
  • 51
  • 1
  • 3
  • 1
    Is not [`TImage.WrapMode = iwFit`](http://docwiki.embarcadero.com/Libraries/XE5/en/FMX.Objects.TImage.WrapMode) what you are looking for? It will keep the proportions of the image. – LU RD Nov 03 '13 at 06:29
  • iwFit is even the default ..... – David Heffernan Nov 03 '13 at 08:06
  • 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 Nov 03 '13 at 16:12
  • 1
    Ahh, [`doc`](http://docwiki.embarcadero.com/Libraries/XE5/en/FMX.Objects.TImageWrapMode) says, that `iwFit` only can shrink the image (proportionally) if it does not fit. Upscaling is not implemented. – LU RD Nov 03 '13 at 19:16

1 Answers1

0

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;
Ivan Revelli
  • 363
  • 4
  • 8