image画图 Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiMultimedia/html/delphi_20061010164801258.html
刚学delphi,想做一个雷达盘。用了两个image,一个做背景图,一个画扫描线,用timer触发事件更新
运行的时候图像闪的很厉害,doublebuffered也设为true了。请达人帮忙改一下是图像流畅一点,别闪了
procedure TForm1.OnDraw;
var
brect : TRect;
bitmap : TBitmap;
centerx,centery: Integer;
radium,pi : Double;
angleh:integer;
Toplacex,Toplacey:integer;
// x,y : Double;
begin
brect:=rect(0,0,Image1.Width,Image1.Height);
radium:=252.0;
pi:=3.14159265;
centerx:=round(Image1.Width/2);
centery:=round(Image1.Height/2);
ScanAngle:=ScanAngle mod (360 div ScanSpeed)+1;
bitmap:=TBitmap.Create;
with bitmap do
begin
Height :=Image1.Height;
Width := Image1.Width;
for angleh:=ScanSpeed*ScanAngle downto ScanSpeed*ScanAngle-ScanWide do
begin//画扫秒指针
Toplacex:=trunc(centerx+radium*sin(angleh/180*pi));
Toplacey:=trunc(centery-radium*cos(angleh/180*pi));
Canvas.Pen.Color:=rgb(colorvalue,colorvalue,colorvalue);
Canvas.Pen.Width:=4; //connectted with R
Canvas.MoveTo(centerx,centery);
Canvas.LineTo(Toplacex,Toplacey);
dec(colorvalue,200 div Scanwide);
end;
end;
Image2.Canvas.CopyRect(brect,bitmap.Canvas,brect);
bitmap.Free;
end;
不要使用使用Image2.Canvas.CopyRec……;
1、用Image1作为底图,上面覆盖一个同样大小的PaintBox1
2、然后直接在PaintBox1.OnPaint事件中直接画扫描指针
3、然后在你的定时器触发事件中调用PaintBox1.Invalidate
使用paintbox试了一下,不像原来闪的那么厉害,但还是会闪,是怎么回事啊
解决了,谢谢哈