0

I have a RAD Studio 12 C++ project which has a TLayout on a form. The TLayout has a number of TRectangle children, and some of them have TText children.

The TRectangles have their own bitmap images in them.

This all displays well on the form, I see the TRectangles and their images, and I see the TText.

However, when I try to capture a bitmap from the TLayout, I get the TLayout and the TRectangles but not the TText. This is the case if the TText is a child of the TLayout or a child of a TRectangle.

I am capturing the bitmap using the Canvas of the TLayout:

void __fastcall TFillScreenForm::CaptureToBitmap(Graphics::TBitmap * Bitmap)
{
    if (Bitmap)
    {
        Bitmap->SetSize(FillLayout->Width, FillLayout->Height);
        // Create a canvas for the bitmap
        TCanvas* Canvas = Bitmap->Canvas;

        // Begin drawing on the canvas
        TRectF Rect(0, 0, Layout->Width, Layout->Height);
        if (Canvas->BeginScene())
        {
            try
            {
                // Clear the canvas
                Canvas->Clear(TAlphaColors::Null);

                // Render the layout onto the canvas
                Layout->PaintTo(Canvas, Rect);
            }
            catch (...)
            {
                // Handle any exceptions if necessary
            }
            // End the drawing scene
            Canvas->EndScene();
        }
    }
}

Is there another way of capturing the TLayout or the TForm in FireMonkey so I also get the TText?

As an example, this is the form with the TLayout:

image

And here is the captured bitmap:

image

I have also tried the snapshot function in TLayout:

Bitmap->SetSize(Layout->Width, Layout->Height);
Bitmap->Assign(Layout->MakeScreenshot());

Both capture only the graphics, not the TText.

I am not sure if this is a FireMonkey bug. If I add a TLabel, this is correctly copied into the bitmap. I need to use TText as I want its greater flexibility.

image

To make sure it isn't anything to do with drawing order, I tried adding a TText on its own away from the other TRectangle objects, but this also is not copied into the bitmap, but displays correctly on the form.

3
  • I don't use C++. In Delphi, you would use Bitmap:=Layout.MakeScreenshot;, so the C++ equivalent of that should work. Commented May 25 at 4:32
  • Odd. Before I posted my previous comment, I tried it to make sure that it would work with a TText. When you tried the TText on its own, did you try calling the TText's own MakeScreenshot, or the form's? If not the former, I'm just curious what the result would be in that case, although it's not a solution. Commented May 25 at 9:46
  • I found the issue. When changing from 3D to 2D, I initially set the parent to the form, then when I added the TLayout, I missed the parent setting, so the Text wasn't a child of the Layout, it was a child of the Form. That's why it worked on the screen but not on the screen shot. When I first tested with the TText, I must have also initially placed this on the form and not the layout. Thanks for all of your help. Commented May 25 at 11:59

1 Answer 1

2

Thanks to Philip J Rayment, I found the issue.

The TText parent was the TForm and not the TLayout, this is why the MakeScreenshot and Canvas capture didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.