Joh*_*ica 7 delphi delphi-xe2 firemonkey
我做了以下代码:
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;
Run Code Online (Sandbox Code Playgroud)
有没有更快的方法在Firemonkey中绘制像素?
我的目标是使用康威的生活游戏制作一个演示程序.
所有的时间都花在执行这两行代码上:
ImageControl1.Canvas.BeginScene;
ImageControl1.Canvas.EndScene;
Run Code Online (Sandbox Code Playgroud)
您可以删除所有使用位图的代码和实际绘制位图的代码,它与运行时没有任何区别.换句话说,瓶颈是场景代码而不是位图代码.我认为没有办法优化它.
我的测试代码如下所示:
Stopwatch := TStopwatch.StartNew;
for i:= 1 to 100 do begin
ImageControl1.Canvas.BeginScene;
ImageControl1.Canvas.EndScene;
end;
ShowMessage(IntToStr(Stopwatch.ElapsedMilliseconds));
Run Code Online (Sandbox Code Playgroud)
这与您的代码相同的经过时间,在我的机器上为1600ms.如果您删除了BeginScene
,DrawBitmap
然后EndScene
调用,那么您的代码将在我的计算机上运行3毫秒.