Delphi FMX And roid FillText速度慢且资源密集

问题描述 投票:1回答:1

我正在使用PaintBox绘制(大)布尔表(大网格模式中的二进制0,1值)。如下面的代码所示。注意:代码已简化,仅绘制随机0和1,以表示问题。我也用完整的代码更新了问题,因为评论者说最初的问题很模糊。

利用FillText绘制(数百个)单个二进制(0或1)值,结果显示为SLOW!。此外,当在PaintBox上进行大量平移时,应用程序会冻结,并强制关闭Android设备。

很明显,FillText对于这种情况是不够的,并且想知道是否有人知道更好的技术?

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;
android delphi text firemonkey paintbox
1个回答
0
投票

您必须通过BeginScene和EndScene封装您的绘图,否则绘图将非常慢:

Canvas.BeginScene;
try
  //all your painting routines here
  Canvas.FillText(...);
  ... 
finally
  Canvas.EndScene;
end;
© www.soinside.com 2019 - 2024. All rights reserved.