I need to draw rotated bitmap on an another bitmap's canvas (main Bitmap). But i have no idea how.
I tried to rotate bitmap with TBitMap.Rotate method and then draw it on main BitMap with TCanvas.DrawBitmap method, but it takes a lot of time (i need to draw ~100 same Bitmaps with different angles):
- resize BMP
- rotate BMP
- draw on another canvas
How to immediately draw rotated bitmap without 1 and 2 steps?
Example:
var
Form1: TForm1;
MainBMP: TBitMap;
SomeItem: TBitMap;
buffBMP: TBitMap;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
begin
MainBMP := TBitMap.Create;
MainBMP.SetSize(screen.Width, screen.Height);
SomeItem := TBitMap.Create;
SomeItem.SetSize(50, 50);
with SomeItem.Canvas do
begin
BeginScene;
FillRect(rectF(0, 0, 50, 50), 5, 20, allCorners, 1);
EndScene;
end;
buffBMP := TBitMap.Create;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
i: integer;
rect, sizeRect: TRectF;
begin
MainBMP.Canvas.BeginScene;
MainBMP.Canvas.Clear($FF777777);
for i := 1 to 10000 do
begin
buffBMP.Assign(SomeItem);
buffBMP.Rotate(random(360));
sizeRect := rectF(0, 0, buffBMP.Width, buffBMP.Height);
rect := sizeRect;
rect.Offset(random(1200), random(600));
MainBMP.Canvas.DrawBitmap(buffBMP, sizeRect, rect, 1);
end;
MainBMP.Canvas.EndScene;
Form1.Canvas.BeginScene;
Form1.Canvas.DrawBitmap(MainBMP, ClientRect, ClientRect, 1);
Form1.Canvas.EndScene;
end;
without
buffBMP.Rotate(random(360));
it takes 16-32 ms. With this method: ~8500 ms
I'm searching for some method like
TCanvas.DrawBitmap(const ABitmap: TBitmap; const SrcRect, DstRect: TRectF; const AOpacity: Single; const HighSpeed: Boolean);
but with added Angle: single parametr
Android. FMX.
Thanks.