Jump to content
mewindy

Save tpaintbox to bitmap

Recommended Posts

HI

I am wanting to capture to a bitmap the contents of a paintbox

after doing a paintto that 

on FMX

(sample code is for VCL. eg using copyrect)

🙂

Thanks!

Brian

 

edit

I got it to work 🙂

using this code on the onpaint event on the paintbox

(I create formimage bitmap first)

  var
 aRect: TRectF;
begin
    aRect := RectF(0,0,formimage.Width,formimage.Height);
 Canvas.DrawBitmap(formimage, aRect, PaintBox1.ClipRect, 1, False);

end;

 

edit

that works ok on windows for copying the contents of a form (i.e form1.paintto)

but that only ends up with a blank image when run on OSX (Mac)

I know you can use a tlayout and use makescreenshot

but that does not always capture all the elements on the form

 

is there a way to capture the contents of a tlayout some other way ? (on OSX/FMX)

Edited by mewindy

Share this post


Link to post
6 hours ago, mewindy said:

I am wanting to capture to a bitmap the contents of a paintbox

You can't, as TPaintBox is painted dynamically on an as-needed basis, so there is no persistent image to "capture".  You need to change your drawing code to draw onto a TBitmap (or any arbitrary TCanvas) instead, and wrap that code into a function that you can call whenever needed.  That way, when the TPaintBox needs to be painted, create a temp TBitmap, have the function draw onto it, and then draw that TBitmap onto the TPaintBox.  When you want to do the "capture", create another temp TBitmap, have the function draw onto it, and then use the TBitmap as needed.

 

This applies to both VCL and FMX, BTW.

Edited by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×