Die*_*urt 2 delphi firemonkey delphi-10.2-tokyo
我需要为我的应用创建裁剪效果。我在 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;
Run Code Online (Sandbox Code Playgroud)
我假设这里Rectangle1有Image1它的Parent:
否则,您将需要考虑Position.X和Position.Y属性的偏移量。
| 归档时间: |
|
| 查看次数: |
2321 次 |
| 最近记录: |