今天要测试在我的delphi程序中加载一些GIF动画,测试一下效果,结果是这样的:当我加载横竖两种流动线条的动画形成一个网格时,由于动画重重叠在一起,CPU利用率马上就上升到了100%左右;如果不重叠的话,当加载20根流动的导线动画时CPU还不怎么明显,当一个窗体加入了200根时,CPU就会上到78%左右了。我的机器是赛扬M 1.2G,256M DDR,30G硬盘的神州天运M120C。源代码如下:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, GIFImage, ExtCtrls, StdCtrls, jpeg; type TForm1 = class(TForm) Button1: TButton; Image1: TImage; Button2: TButton; Button3: TButton; Button4: TButton; Image2: TImage; Image3: TImage; Image4: TImage; Image5: TImage; Image6: TImage; Image7: TImage; Image8: TImage; procedure Button4Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; MxArray : array of TImage; KxArray : array of TImage; implementation {$R *.dfm} procedure TForm1.Button4Click(Sender: TObject); begin application.Terminate ; end; procedure TForm1.Button1Click(Sender: TObject); var filename : String; begin filename := './mx-l.gif'; Image2.Picture.LoadFromFile(filename); Image2.Width := 200; Image2.Height := 4; filename := './mx-r.gif'; Image3.Picture.LoadFromFile(filename); Image3.Width := 200; Image3.Height := 4; filename := './kx-u.gif'; Image4.Picture.LoadFromFile(filename); Image4.Width := 4; Image4.Height := 200; filename := './kx-d.gif'; Image5.Picture.LoadFromFile(filename); Image5.Width := 4; Image5.Height := 200; filename := './mx-l.gif'; Image6.Picture.LoadFromFile(filename); Image6.Width := 600; Image6.Height := 10; if Image6.Width > 1024 then Image6.Stretch := true; filename := './mx-r.gif'; Image7.Picture.LoadFromFile(filename); Image7.Width := 600; Image7.Height := 10; if Image7.Width > 1024 then Image7.Stretch := true; end; procedure TForm1.Button2Click(Sender: TObject); var filename : String; begin filename := './038.gif'; Image1.Picture.LoadFromFile(filename); end; procedure TForm1.Button3Click(Sender: TObject); var i,j,k : Integer; filename : String; begin k:=200; SetLength(MxArray,k); SetLength(KxArray,k); for i:=0 to k-1 do begin filename := './mx-r.gif'; MxArray[i] := TImage.Create(self); MxArray[i].Parent := self; MxArray[i].Width := 400; MxArray[i].Height:= 2; MxArray[i].Top := 160+i*3; MxArray[i].Left := 120; //MxArray[i].Picture.LoadFromFile(filename); //MxArray[i].Show ; filename := './kx-d.gif'; KxArray[i] := TImage.Create(self); KxArray[i].Parent := self; KxArray[i].Width := 2; KxArray[i].Height:= 400; KxArray[i].Top := 160; KxArray[i].Left := 120+i*12; KxArray[i].Picture.LoadFromFile(filename); KxArray[i].Show ; end; { 经测试:加载Gif动画,如果的两个以上动画是重叠在一起的,会引起CPU利用率上升 到100%(但如果只是动画与静态画面重叠的话是没有问题的);另外,如果一个窗体中加载 导线200根的话会使用CPU上到78%左右。故不要在程序中加载过多幅动画,并且注意不要 动画不要重叠。 tls 06.11.08 } end; end.