FMX Android TControl.MakeScreenShot or TCanvas.FillText always generate black block around fonts

  

I want to create a picture with “white background and black labels” and share it using intent. But my picture always generate black block around all fonts.

It’s been 2 days now I’m stuck on this problems. Anybody has solution or can point me to the right direction? or any workaround if it’s still a bug from developer?

I’m using 10.2

Thank you.

Edit: Adding example

Code

unit UTest;

interface

uses

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,

FMX.Objects, FMX.Controls.Presentation;

type

TFTest = class(TForm)
Rectangle1: TRectangle;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Image1: TImage;
Button1: TButton;
Button2: TButton;
Image2: TImage;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var

FTest: TFTest;

implementation

{$R *.fmx}

Uses

System.IOUtils;

procedure TFTest.Button1Click(Sender: TObject);

begin

Image2.Bitmap := Rectangle1.MakeScreenshot;

end;

procedure TFTest.Button2Click(Sender: TObject);

var

mrect:trect;

begin

Image1.Bitmap.SetSize(Trunc(Image1.Width * Image1.Canvas.Scale),

Trunc(Image1.Height * Image1.Canvas.Scale));

Image1.bitmap.Canvas.BeginScene;
Image1.Bitmap.canvas.Clear(TAlphaColors.White);
Image1.bitmap.Canvas.Stroke.Thickness := 1;
Image1.bitmap.Canvas.Stroke.Color := TAlphaColorRec.Black;
Image1.Bitmap.canvas.Stroke.Kind := TBrushKind.bkSolid;
Image1.bitmap.Canvas.Fill.Color := TAlphaColors.Black;
Image1.Bitmap.Canvas.Fill.DefaultColor:=TAlphaColors.White;
Image1.Bitmap.Canvas.Font.Size:=10;
Image1.Bitmap.Canvas.Font.Family:=’Arial’;
Image1.Bitmap.Canvas.Font.Style:=[TFontStyle.fsbold];
Image1.bitmap.canvas.Blending:=false;

Image1.Bitmap.Canvas.DrawLine(PointF(20, 10), PointF(330, 10), 1);

mRect.Create(20, 10, 180, 30);
Image1.bitmap.Canvas.filltext(mRect, ‘DD:MM:YY HH:MM’, false, 0, [],TTextAlign.Leading, TTextAlign.Center);
mRect.Create(180, 10, 330, 30);
Image1.bitmap.Canvas.filltext(mRect, ‘SHID/CNAME’, false, 1, [],TTextAlign.Trailing, TTextAlign.Center);

Image1.Bitmap.Canvas.DrawLine(PointF(20, 30), PointF(330, 30), 1);

Image1.bitmap.Canvas.EndScene;
{$IFDEF ANDROID}
image1.bitmap.SaveToFile(TPath.GetHomePath() + TPath.DirectorySeparatorChar + ‘screenshot.jpg’);
image2.Bitmap.LoadFromFile(TPath.GetHomePath() + TPath.DirectorySeparatorChar + ‘screenshot.jpg’);
{$ENDIF}
{$IFDEF MSWINDOWS}
image1.Bitmap.SaveToFile(‘E:\screenshot.jpg’);
image2.Bitmap.LoadFromFile(‘E:\screenshot.jpg’);
{$ENDIF}
end;

procedure TFTest.Button3Click(Sender: TObject);
var
bmp: TBitmap;
begin
bmp := TBitmap.Create;
bmp.Width := Image2.bitmap.Width;
bmp.Height := Image2.bitmap.Height;
bmp := Rectangle1.MakeScreenshot;
{$IFDEF ANDROID}
bmp.SaveToFile(TPath.GetHomePath() + TPath.DirectorySeparatorChar + ‘screenshot.jpg’);
image2.Bitmap.LoadFromFile(TPath.GetHomePath() + TPath.DirectorySeparatorChar + ‘screenshot.jpg’);
{$ENDIF}
{$IFDEF MSWINDOWS}
bmp.SaveToFile(‘E:\screenshot.jpg’);
image2.Bitmap.LoadFromFile(‘E:\screenshot.jpg’);
{$ENDIF}
end;

procedure TFTest.Button4Click(Sender: TObject);
begin
image1.Bitmap := nil;
image2.Bitmap := nil;
end;

end.

Form

object FTest: TFTest
Left = 0
Top = 0
Caption = ‘Form1’
ClientHeight = 530
ClientWidth = 360
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 3
object Rectangle1: TRectangle
Fill.Color = claWhite
Position.X = 8.000000000000000000
Position.Y = 8.000000000000000000
Size.Width = 345.000000000000000000
Size.Height = 121.000000000000000000
Size.PlatformDefault = False
Stroke.Kind = None
object Label1: TLabel
Align = Top
Size.Width = 345.000000000000000000
Size.Height = 23.000000000000000000
Size.PlatformDefault = False
TextSettings.HorzAlign = Center
Text = ‘Label1’
TabOrder = 0
end
object Label2: TLabel
Position.X = 23.000000000000000000
Position.Y = 80.000000000000000000
Text = ‘Label2’
TabOrder = 1
end
object Label3: TLabel
Position.X = 23.000000000000000000
Position.Y = 48.000000000000000000
Text = ‘Label3’
TabOrder = 2
end
end
object Image1: TImage
MultiResBitmap =
Position.X = 8.000000000000000000
Position.Y = 136.000000000000000000
Size.Width = 345.000000000000000000
Size.Height = 121.000000000000000000
Size.PlatformDefault = False
end
object Button1: TButton
Position.X = 8.000000000000000000
Position.Y = 264.000000000000000000
Size.Width = 345.000000000000000000
Size.Height = 44.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
Text = ‘TLayout.MakeScreenShot (No Saving)’
OnClick = Button1Click
end
object Button2: TButton
Position.X = 8.000000000000000000
Position.Y = 360.000000000000000000
Size.Width = 193.000000000000000000
Size.Height = 44.000000000000000000
Size.PlatformDefault = False
TabOrder = 3
Text = ‘TCanvas.FillRect’
OnClick = Button2Click
end
object Image2: TImage
MultiResBitmap =
Position.X = 8.000000000000000000
Position.Y = 408.000000000000000000
Size.Width = 345.000000000000000000
Size.Height = 121.000000000000000000
Size.PlatformDefault = False
end
object Button3: TButton
Position.X = 8.000000000000000000
Position.Y = 312.000000000000000000
Size.Width = 345.000000000000000000
Size.Height = 44.000000000000000000
Size.PlatformDefault = False
TabOrder = 5
Text = ‘TLayout.MakeScreenShot (Saving)’
OnClick = Button3Click
end
object Button4: TButton
Position.X = 208.000000000000000000
Position.Y = 360.000000000000000000
Size.Width = 137.000000000000000000
Size.Height = 44.000000000000000000
Size.PlatformDefault = False
TabOrder = 6
Text = ‘Image NIL’
OnClick = Button4Click
end
end

On windows everything is normal, but when i run it on android:
TLayout MakeScreenShot without saving has gray block around fonts.
TLayout MakeScreenShot with saving has black block around fonts.
TCanvas FillRect has black block around fonts.

Canvas FillText

Comments are closed.