如何用Image控件循环显示某个目录下的图片,该目录下的图片可随意增加减少,并用Timer控制循环显示图片的时间.在线等,问题解决立即给分!

解决方案 »

  1.   

    function TForm1.ListDir(Path: string; List: TStringList): Integer; //非递归遍历文件夹
    var
    filename:string;
    j:integer;
    i:boolean;
    filedata:Twin32finDdata;
    fhandle:Thandle;
    begin
    // 此函数返回本目录下的文件夹和文件。
       j:=0;
    if path[length(path)]<>'\' then
       path:=path+'\';//保证patch的格式为?:\???\??\的形式
     try
        fhandle:=findfirstfile(pchar(path+'*.*'),filedata);
        if (fhandle=INVALID_HANDLE_VALUE) then  //INVALID_HANDLE_VALUE api自定义常量
            begin
           windows.findclose(fhandle);
           result:=0;
           end;
           list.Add(path+strpas(filedata.cFileName));
           i:=findnextfile(fhandle,filedata);
        while I do
          begin
           inc(j);
           list.Add(path+strpas(filedata.cFileName));
           i:=findnextfile(fhandle,filedata);
          end;
           result:=j;
           windows.findclose(fhandle);
       except
           result:=0;
       end;
    end; ///非递归循环,递归循环自己调用
      

  2.   

    fhandle:=findfirstfile(pchar(path+'*.*'),filedata);
    *.*可以换成你需要的'*.bmp'.
      

  3.   

    目录里的文件我能找出来,就是如何在Image控件循环上显示的问题,并如何用Timer控件控制显示的时间.
      

  4.   

    把所有文件找出来放在一个TStringList里,Form上加一个Timer,把Internal设的大些,比如5000,每次OnTimer事件中读取下一个文件并显示在Image中。读到最后一个时跳到第一个读。
      

  5.   

    能详细点吗?我现在用TStringList变量List1获得了文件名和路径,我要怎样用Image1把它一张一张读出来,最好能看点代码.
      

  6.   

    这样for i:=0 to youlist.count-1 do
       begin
       if not image1.picture.bitmap.empty then 
         begin
         image1.Picture.Bitmap.FreeImage; //清除内存
         image1.picture.bitmap.loadfromfile(youlist.string[i]);//显示下一个
         end;
      

  7.   

    Files: TStringList;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if Files.Count=0 then Exit;
      if Timer1.Tag>Files.Count then Timer1.Tag:=0;
      Image1.Picture.Bitmap.LoadFromFile(Files[Timer1.Tag]);
      Timer1.Tag:=Timer1.Tag+1;
    end;