Saving content of TPaintBox Canvas to a Bitmap (and/or a file) in Delphi 10.3 Firemonkey

  

Delphi 10.3.3 Firemonkey App for Android.
I’m drawing a lots of objects in TPaintBox Canvas in the OnPaint event.
Now I need to save the whole content of PaintBox.Canvas in a Bitmap, and, finally, in a file.
How this can be done?
Read RAD docs, googled internet – cannot find a solution.

UPDATE1:

Following comments from @MBo , @Remy-Lebeau , @Adam-Henderson I tried, but it is 50% success only…

I created

procedure GameCanvasPaint(Canvas: TCanvas);

In PaintBox OnPaint event I’m calling it, drawint successfull:

procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
begin
GameCanvasPaint( Canvas );
end;

and now I want to create Bitmap and share it, also calling same paining function:

procedure TForm1.ShowShareSheetAction1BeforeExecute(Sender: TObject);
begin
// g_bmp_share is TBitmap already created earlier
g_bmp_share.SetSize( Paintbox1.Canvas.Width, Paintbox1.Canvas.Height );
g_bmp_share.Canvas.Clear($FFFFFF);
GameCanvasPaint( g_bmp_share.Canvas );
ShowShareSheetAction1.Bitmap.Assign( g_bmp_share );
end;

RESULT: Shared picture with black color… Nothing on it, only black. Who can advise why?

Comments are closed.