码迷,mamicode.com
首页 > 其他好文 > 详细

简单的 "双缓冲" 绘图的例子(研究一下)

时间:2016-03-31 21:40:41      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

所谓双缓冲就是先画到内存画布(如: TBitmap), 然后再转帖到目的地.

譬如下面小程序:


 

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Interval := 100;
  Color := clWhite;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Canvas.Pen.Color := Random($FFFFFF);
  Canvas.MoveTo(Random(ClientWidth), Random(ClientHeight));
  Canvas.LineTo(Random(ClientWidth), Random(ClientHeight));
end;


改为双缓冲绘图可以是:


 

var
  bit: TBitmap;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Interval := 100;
  bit := TBitmap.Create;
  bit.Width := ClientWidth;
  bit.Height := ClientHeight;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  bit.Canvas.Pen.Color := Random($FFFFFF);
  bit.Canvas.MoveTo(Random(bit.Width), Random(bit.Height));
  bit.Canvas.LineTo(Random(bit.Width), Random(bit.Height));
  Self.Canvas.Draw(0, 0, bit);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bit.Free;
end;

http://www.cnblogs.com/del/archive/2010/04/19/1715779.html

简单的 "双缓冲" 绘图的例子(研究一下)

标签:

原文地址:http://www.cnblogs.com/findumars/p/5342735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!