我编写了以下代码:
procedure TForm15.Button1Click(Sender: TObject);
var
Bitmap1: TBitmap;
im: TImageControl;
Color: TColor;
Scanline: PAlphaColorArray;
x,y,i: Integer;
begin
for i:= 1 to 100 do begin
im:= ImageControl1;
Bitmap1:= TBitmap.Create(100,100);
try
for y:= 0 to 99 do begin
ScanLine:= Bitmap1.ScanLine[y];
for x:= 0 to 99 do begin
ScanLine[x]:= Random(MaxInt);
end;
end;
ImageControl1.Canvas.BeginScene;
ImageControl1.Canvas.DrawBitmap(Bitmap1, RectF(0,0,Bitmap1.Width, Bitmap1.Height)
,im.ParentedRect,1,true);
ImageControl1.Canvas.EndScene;
finally
Bitmap1.Free;
end;
end;
end;
在 Firemonkey 中是否有更快的绘制像素的方法?
我的目标是使用康威的生命游戏制作一个演示程序。
所有的时间都花在执行这两行代码上:
ImageControl1.Canvas.BeginScene;
ImageControl1.Canvas.EndScene;
您可以删除所有使用位图的代码和实际绘制位图的代码,这对运行时没有丝毫影响。换句话说,瓶颈是场景代码而不是位图代码。我认为你没有办法优化它。
我的测试代码如下所示:
Stopwatch := TStopwatch.StartNew;
for i:= 1 to 100 do begin
ImageControl1.Canvas.BeginScene;
ImageControl1.Canvas.EndScene;
end;
ShowMessage(IntToStr(Stopwatch.ElapsedMilliseconds));
这与您的代码具有相同的运行时间,在我的机器上为 1600 毫秒。如果您删除BeginScene
, DrawBitmap
and EndScene
调用,然后你的代码在我的机器上运行 3 毫秒。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)