所謂雙緩沖就是先畫到內存畫布(如: 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;
TookiQ 需要的是 GDI+ 的, 道理都一樣.