我正在用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;
答案 0 :(得分:0)
您必须使用BeginScene和EndScene封装您的图形,否则图形会很慢:
Canvas.BeginScene;
try
//all your painting routines here
Canvas.FillText(...);
...
finally
Canvas.EndScene;
end;