双缓冲画图的问题(50分)

  • 主题发起人 主题发起人 anndy1999
  • 开始时间 开始时间
A

anndy1999

Unregistered / Unconfirmed
GUEST, unregistred user!
我用双缓冲画图,但没画出来,不知下面的代码哪儿搞错了,还望指教!
var
BackMap : TBitMap;

procedure TAFXTest.DrawMap();
var
mx, my : Double;
i : Integer;
x, y : Int64;
moveFlag : Boolean;
begin
moveFlag := TRUE;
PaintBox.Canvas.Pen.Mode :=pmCopy;
BackMap := TBitMap.Create;
BackMap.Width := PaintBox.Width;
BackMap.Height := PaintBox.Height;
BackMap.Canvas.CopyRect(Rect(0,0,PaintBox.Width,PaintBox.Height),PaintBox.Canvas,
Rect(0,0,PaintBox.Width,PaintBox.Height));
for i:=0 to POINTNUM-1 do
begin
Global.LgLtToXY(MAP[0].Lon,MAP[0].Lat,MAP[i+1].Lon,MAP[i+1].Lat,mx,my);
x := Round(Screen.Width/2+(mx/2) * ZOOM );
y := Round(Screen.Height/2-(my/2) * ZOOM );
if moveFlag=TRUE then
begin
BackMap.Canvas.MoveTo(x,y);
moveFlag := FALSE;
end
else
BackMap.Canvas.LineTo(x,y);
end;
MAP := nil;
PaintBox.Canvas.CopyRect(Rect(0,0,PaintBox.Width,PaintBox.Height),BackMap.Canvas,
Rect(0,0,BackMap.Width,BackMap.Height));
BackMap.Free;
end;
 
都没有肯帮帮偶吗~~~~~~~~~~~
 
你在BackMap.Free前加上BackMap.SaveToFile('C:/test.bmp');存到磁盘上看看画出来的是什么?
 
你的循环判断出了问题吧,用
BackMap.Canvas.MoveTo(10,10);
BackMap.Canvas.LineTo(40,60);
代换你的循环,试试看
 
不需要这么麻烦
VCL本身提供了双缓存模式
TWinControl.DoubleBuffered := True
 
不用CopyRect,用canvas.draw或bitblt试试。
 
后退
顶部