如何在Firemonkey中拉伸图像? [英] How to stretch image in Firemonkey?
问题描述
我想将图像的大小调整为64 * 64的预定义位图,无论其当前尺寸和宽高比如何。我尝试了 Bitmap.ReSize
但保持了宽高比。我尝试 TImage
并将 WrapMode
设置为 iwStretch
。这在一定程度上起作用,因为它确实重新缩放了我想要的图像,但我找不到从 TImage
中获取该图像的方法。 TImage
的位图
属性仍包含原始位图。
I would like to resize an image to a predefined bitmap of 64 * 64, regardless of its current dimensions and aspect ratio. I tried Bitmap.ReSize
but that keeps the aspect ratio. I tried TImage
and set the WrapMode
to iwStretch
. That works to a certain extent in that it indeed rescales the image as I want it, but I can't find a way to get that image out of the TImage
. The Bitmap
property of TImage
still contains the original bitmap.
有人知道如何从屏幕上显示的 TImage
获取图像吗?或者甚至更好:指向一个能够进行这种调整和拉伸的功能?如果有,我错过了。
Does anybody know how to fetch the Image from a TImage
as it is shown on the screen? Or even better: point me to a function that does this kind of resizing and stretching? If there is one, I have missed it.
感谢您的时间。
推荐答案
要在 Fmx
中拉伸图像,您不需要使用 TImage
。我知道你真的不想使用 TImage
,解决方案如下:
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;
你让 bmpB.Canvas
画出 bmpA
位图并根据 src
和 trg $ c同时调整图像大小$ c>矩形。
You let the bmpB.Canvas
draw the bmpA
bitmap and resizing the image at the same time according src
and trg
rectangles.
这篇关于如何在Firemonkey中拉伸图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!