我正在用 PaintBox 绘制一个(大)布尔表(大网格图案中的二进制 0,1 值)。如下面的代码所示。注意:代码是简化的,只画了随机的0和1,来表示问题。我还用完整的代码更新了这个问题,因为评论者说最初的问题很模糊。
利用 FillText 来绘制(数百)个单独的二进制(0 或 1)值,结果是慢!此外,当在 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;