我想在Firemonkey中裁剪一張圖片或一個矩形。我怎樣才能做到這一點?

uj5u.com熱心網友回復:
我已經為你上傳了一個演示。
下面是代碼,如果你不想弄亂它,請下載演示。
unit Unit1;
介面
us
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants。
FMX.Type, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.物件。
型別
TMain = class(TForm)
影像。TImage;
Rectangle_CropPos: TRectangle;
Timer_Startup: TTimer。
procedure Timer_StartupTimer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations } public
end;
var
Main: TMain;
implementation; implementation
{$R *.fmx}
用途 Unit2;
程式 TMain.Timer_StartupTimer(Sender: TObject);
var
lBmp: TBitmap。
xScale, yScale, scale: 擴展。
iRect: TRect;
OffsetX, OffsetY: 擴展。
BmpHwRatio: 擴展的。
DispRatio: 擴展的。
begin
Timer_Startup.Enabled:=False;
// --------------------------
if Rectangle_CropPos.Visible then
begin
lBmp := TBitmap.Create;
try
xScale := Image.Bitmap.Width / Image.Width。
yScale := Image.Bitmap.Height / Image.Height。
if xScale > yScale
then yscale := xScale
else xscale := yScale;
lBmp.Width := round(Rectangle_CropPos.Width * xScale);
lBmp.Height := round(Rectangle_CropPos.Height * yScale)。
//增加了偏移條款來補償之間的空間。
//圖片和Image1的邊框。
offsetx := (Image.Width - Image.Bitmap.Width / xscale) / 2;
offsety := (Image.Height - Image.Bitmap.Height / yscale) / 2;
//你可以不進行偏移量計算的測驗。
// offsetx :=0;.
//offsety :=0;
//offset terms added here
iRect.Left := round((Rectangle_CropPos.Position.X - offsetx) * xscale)。
iRect.Top := round((Rectangle_CropPos.Position.Y - offsety) * yscale);
iRect.Width := round(Rectangle_CropPos.Width * xscale);
iRect.Height := round(Rectangle_CropPos.Height * yscale)。
if iRect.Left < 0 then iRect.Left :=0;
if iRect.Top < 0 then iRect.Top :=0。
if iRect.Width < 1 then iRect.Width :=1;
if iRect.Height > (LBMp.Height-1) then iRect.Height := LBmp.Height;
lBmp.CopyFromBitmap(Image.Bitmap, iRect, 0, 0) 。
if (fImagePreview.Visible=False) then
fImagePreview.Show;
fImagePreview.Left:=Self.Left Self.ClientWidth 3;
fImagePreview.Top:=Self.Top;
fImagePreview.Image.Bitmap.Assign(lBmp)。
最終
FreeAndNil(lBmp)。
end。
end;
{
否則
開始
Rectangle_CropPos.Visible := True;
Rectangle_CropPos.Width := Round(Panel1.Width * 0.5);
Rectangle_CropPos.Height := Round(Rectangle_CropPos.Width * 1.41);
Rectangle_CropPos.Position.X := Round(Panel1.Width * 0.5)-(Rectangle_CropPos.Width * 0.5);
Rectangle_CropPos.Position.Y := Round(Panel1.Height * 0.5)-(Rectangle_CropPos.Height * 0.5)。
結束。
}
end。
procedure TMain.FormCreate(Sender: TObject);
begin
Timer_Startup.Enabled:=True。
end;
end.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/329633.html
標籤:
上一篇:如何在FMX中隱藏TTabControl的所有標簽頭?
下一篇:帶有型別條件的C 模板

