Delphi FMX Android FillText is Slow and Resource intensive

  

I am drawing a (large) Boolean Table (Binary 0,1 values in a large grid pattern) with a PaintBox. As in the code below.
Note: The code is simplified, only drawing random 0 and 1, to represent the problem.
Also I have updated the question with the full code, since the commenter stated the initial question was vague.

Utilising the FillText to draw the (hundreds) of individual binary (0 or 1) values turned out to be SLOW!.
Also when doing a lot of panning across the PaintBox, the app would freeze, and force close on the Android device.

So clearly the FillText is not sufficient for this case, and are wondering if anyone knows of a better technique?

procedure TMainWin.PaintBoxPaint(Sender: TObject; Canvas: TCanvas);
VAR Fcstroke:TStrokeBrush;
xp,yp,Tsze:INTEGER;
tw,th:SINGLE;
p1,p2:TPointF;
MyRect:TRectF;
begin
Canvas.BeginScene;
// Clear
Canvas.Clear(TAlphaColorRec.Beige);
Canvas.Fill.Color:= TAlphaColorRec.Black;
Canvas.Fill.Kind:= TBrushKind.Solid;
// Text Prop
Canvas.Font.Family:= ‘Roboto’;
Canvas.Font.Style:= [];
Canvas.Font.Size:= 40;
Canvas.Stroke.Thickness:= 2;
Canvas.Stroke.Kind:= TBrushKind.Solid;
Canvas.Stroke.DefaultColor:= TAlphaColorRec.Black;
tw:= Canvas.TextWidth(‘0’)*1.2;
th:= Canvas.TextHeight(‘0′);
Fcstroke:= TStrokeBrush.Create(TBrushKind.Solid,TAlphaColorRec.Green);
Fcstroke.DefaultColor:= TAlphaColorRec.Green;
Fcstroke.Thickness:= 2;
// Table
Tsze:= 50;
FOR yp:= 1 TO Tsze DO
BEGIN
// Horz table Line
p1:= TPointF.Create( tw,yp*th);
p2:= TPointF.Create((Tsze+1)*tw,yp*th);
Canvas.DrawLine(p1,p2,1,Fcstroke);
// Vert table Line
p1:= TPointF.Create(yp*tw, th);
p2:= TPointF.Create(yp*tw,(Tsze+1)*th);
Canvas.DrawLine(p1,p2,1,Fcstroke);
// Text
FOR xp:= 1 TO Tsze DO
BEGIN
MyRect:= TRectF.Create(xp*tw,yp*th,xp*tw+tw,yp*th+th);
IF (Random(10)>5) THEN
Canvas.FillText(MyRect,’0′,False,100,[],TTextAlign.Center,TTextAlign.Center)
ELSE
Canvas.FillText(MyRect,’1’,False,100,[],TTextAlign.Center,TTextAlign.Center);
END;
END;
// End
Canvas.EndScene;
end;

Comments are closed.