我用三个TIMER同时画三个图,可是第一个图还可以,第二个太慢,第三个简直就不画!我是用TIMER,一个一个点画的心电图,由于需要控制速度和波幅等,必须用TIMER控制。
听说多线程可以解决冲突问题,但是我要在1/128秒就画一个点,那么时间又无法控制。
请问大家,有何高见。
听说多线程可以解决冲突问题,但是我要在1/128秒就画一个点,那么时间又无法控制。
请问大家,有何高见。
因为VCL的Canvas上作图时要用Synchronize来作,这样图才不会把画布画“脏”,也只有这样才是安全的。而Synchronize其实是让方法丢给主给线程来执行的,这样能避免线程冲突;这样就和用Timer估计效果类似了。
-------我推测的
不过你可以试试看,毕竟实际最有说服力
TIMER一次就分别画三个点,不就同步了吗?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
Timer3: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
private
{ Private declarations }
public
x,y,z:integer;
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
begin
LABEL1.Canvas.LineTo(x,LABEL1.Height);
inc(x);
LABEL1.Canvas.MoveTo(x,0);
end;procedure TForm1.Timer2Timer(Sender: TObject);
begin
LABEL2.Canvas.LineTo(y,LABEL2.Height);
inc(y);
LABEL2.Canvas.MoveTo(y,0);
end;procedure TForm1.Timer3Timer(Sender: TObject);
begin
LABEL3.Canvas.LineTo(z,LABEL3.Height);
inc(z);
LABEL3.Canvas.MoveTo(z,0);
end;end.
楼上各位说的情况没出现阿?
我已经解决。是用多线程。
另外,画图最忌讳重叠,我发现一个大的IMAGE重叠,画起来简直就是恶梦。
谢谢!