How to stretch image in Firemonkey?

霸气de小男生 提交于 2019-12-06 00:42:05

To stretch an image in Fmx you don't need to use a TImage. I understand you do not really want to use a TImage, and the solution is as follows:

var
  bmpA, bmpB: TBitmap;
  src, trg: TRectF;
begin
  bmpA := nil;
  bmpB := nil;
  try
    bmpA := TBitmap.Create;
    bmpA.LoadFromFile('C:\tmp\Imgs\149265645.jpg');

    bmpB:= TBitmap.Create;
    bmpB.SetSize(64, 64);

    src := RectF(0, 0, bmpA.Width, bmpA.Height);
    trg := RectF(0, 0, 64, 64);

    bmpB.Canvas.BeginScene;
    bmpB.Canvas.DrawBitmap(bmpA, src, trg, 1);
    bmpB.Canvas.EndScene;

    bmpB.SaveToFile('C:\tmp\Imgs\149265645_take_two.bmp');
  finally
    bmpA.Free;
    bmpB.Free;
  end;
end;

You let the bmpB.Canvas draw the bmpA bitmap and resizing the image at the same time according src and trg rectangles.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!