我需要为我的应用程序创建裁剪效果。我在 TImage 上有一个 TRectangle,我需要当用户按下保存按钮时,仅复制 TRectangle 使用的区域。有什么方法可以从 Image1.Bitmap 中只剪切特定区域吗?我打印了一张图像以更好地说明我需要的内容:
最佳答案
这是一个适合我的示例:
procedure TForm1.Button1Click(Sender: TObject);
var
Bmp: TBitmap;
xScale, yScale: extended;
iRect: TRect;
begin
Bmp := TBitmap.Create;
xScale := Image1.Bitmap.Width / Image1.Width;
yScale := Image1.Bitmap.Height / Image1.Height;
try
Bmp.Width := round(Rectangle1.Width * xScale);
Bmp.Height := round(Rectangle1.Height * yScale);
iRect.Left := round(Rectangle1.Position.X * xScale);
iRect.Top := round(Rectangle1.Position.Y * yScale);
iRect.Width := round(Rectangle1.Width * xScale);
iRect.Height := round(Rectangle1.Height * yScale);
Bmp.CopyFromBitmap(Image1.Bitmap, iRect, 0, 0);
Image2.Bitmap := Bmp
finally
Bmp.Free;
end;
end;
我在这里假设 Rectangle1
将 Image1
作为其 Parent
:
否则,您将需要考虑 Position.X
和 Position.Y
属性的偏移量。
关于delphi - 如何使用firemonkey在选定区域裁剪位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46880322/