在窗体下有timer1,lmage1二个控件.效果是让图片一张张显示.
时钟属性为 真和1000毫秒.可是用下面代码怎么也运行不了.用了随机函数才能显示出来,可是显示却是随机的图片,不是按顺序来的.
各位大虾有什么好的思路不防教教我.还有怎么写才能像我说的效果显示出来.
procedure TForm8.Timer1Timer(Sender: TObject);
var
chajutu:integer;
begin
//randomize;
//chajutu:=random(4);
case chajutu of
1:image1.Picture.LoadFromFile('茶具\自动流水雕龙骨瓷茶具.jpg');
2:image1.Picture.LoadFromFile('茶具\龙头老大 紫砂茶具.jpg');
3:image1.Picture.LoadFromFile('茶具\茶叶加茶具.jpg');
4:image1.Picture.LoadFromFile('茶具\茶叶和茶具.jpg');
end;
end;
时钟属性为 真和1000毫秒.可是用下面代码怎么也运行不了.用了随机函数才能显示出来,可是显示却是随机的图片,不是按顺序来的.
各位大虾有什么好的思路不防教教我.还有怎么写才能像我说的效果显示出来.
procedure TForm8.Timer1Timer(Sender: TObject);
var
chajutu:integer;
begin
//randomize;
//chajutu:=random(4);
case chajutu of
1:image1.Picture.LoadFromFile('茶具\自动流水雕龙骨瓷茶具.jpg');
2:image1.Picture.LoadFromFile('茶具\龙头老大 紫砂茶具.jpg');
3:image1.Picture.LoadFromFile('茶具\茶叶加茶具.jpg');
4:image1.Picture.LoadFromFile('茶具\茶叶和茶具.jpg');
end;
end;
begin
Timer1.Enabled := false;
....
Timer1.Enabled := true;
end;如果有可能,最好是用线程来装载图片,否则图片稍微大一点就会有停顿的感觉
如果图片超过了显示区域大小,TImage在装载成功后还会缩放一下显示到TImage.Canvas,这些操作如果能在线程里完成,那前端显示才会自然流畅
在create的时候chajutu:=0
Timer1Timer中,就可以写了,加上个判断
if chajutu = 4 then
chajutu :=0或者使用StringList把路径都放到里面去,然后循环读取到最后一条的时候
在指到位置0
思路都一样。
Form1: TForm1;
Num: Integer;//全局变量
implementation{$R *.dfm}
procedure TForm1.Timer(Sender: TObject);begin
Num:=Num+1;
begin
case Num of
1: Image1.Picture.LoadFromFile('Picture\cat1.jpg');
2: Image1.Picture.LoadFromFile('Picture\cat2.jpg');
3: Image1.Picture.LoadFromFile('Picture\cat3.jpg');
4: Image1.Picture.LoadFromFile('Picture\cat4.jpg');
end; if Num=4 then
Num:=1;
end;
end;
Form1: TForm1;
PictureIndex: Integer;//全局变量
PictureName: array of string;
implementation {$R *.dfm}
procedure TForm1.Timer(Sender: TObject); begin
Image1.Picture.LoadFromFile(PictureName[PictureIndex]);
inc(PictureIndex);
if PictureIndex> High(PictureName) then
PictureName:= Low(PictureName);
end;其中PictureName为保存要显示的图片的文件名,若名称固定则可声明为const,若为存储在某个指定目录的不确定数量图片则可在FormCreate中搜索并存储文件名在PictureName中