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 TRectangle
s have their own bitmap images in them.
This all displays well on the form, I see the TRectangle
s 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 TRectangle
s 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
:
And here is the captured bitmap:
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.
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.
Bitmap:=Layout.MakeScreenshot;
, so the C++ equivalent of that should work.TText
. When you tried theTText
on its own, did you try calling theTText
's ownMakeScreenshot
, 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.