装载一张图片,可出现的这样一个小问题。
procedure TForm1.FormCreate(Sender: TObject);
var
  s1:string;
begin
  s1:='C:\Program Files\Borland\Delphi7\BORLAND.GIF';
if fileexists(s1) then
image1.Picture.LoadFromFile(s1);
end;刚开始执行的时候,总是出错
unknown picture file extension(.GIF)可是在设计窗体时,如果先显示图片,就是先将image1的picture属性添加图片并且运行后,上述代码就可以正常运行了。为什么会有这样的问题?

解决方案 »

  1.   

    s1:='C:\\Program Files\\Borland\\Delphi7\\BORLAND.GIF';
    因为\在delphi的字符串中是转义字符
      

  2.   

    我运行了一下,还是出现unknown picture file extension(.GIF)这样的错误
      

  3.   

    先显示图片也是不行的.除非你用了第三方控件.比如rx的gif控件,你设计期加入pictiure之后,你看看
    uses段有没有什么变化.
      

  4.   

    在我的D7中,Timage是不支持GIF的呀,即使在设计阶段调入,也是不允许的
      

  5.   

    不支持Gif
    如果是JPG,出错,是因为你没有 users Jpeg 单元!
      

  6.   

    在USER中加入 GIFIMAGE就可以了
    procedure TFormMain.ButtonConvertClick(Sender: TObject);
    var
      GIF : TGIFImage;
      Bitmap : TBitmap;
    begin
      ButtonConvert.Enabled := False;
      try
        GIF := TGIFImage.Create;
        try
          GIF.OnProgress := OnProgress;
          // Load the GIF that will be converted
          GIF.LoadFromFile('test.gif');
          // Display the GIF
          ImageGIF.Picture.Assign(GIF);
          // Clear previous BMP view
          ImageBMP.Picture.Assign(nil);      ShowMessage('This demo loads a GIF from the file TEST.GIF,'+#13+
            'converts it to a bitmap and saves it as TEST.BMP');
          Bitmap := TBitmap.Create;
          try
            // Convert the GIF to a BMP
            Bitmap.Assign(GIF);
            // Save the BMP
            Bitmap.SaveToFile('test.bmp');
            // Display the BMP
            ImageBMP.Picture.Assign(Bitmap);
          finally
            Bitmap.Free;
          end;
        finally
          GIF.Free;
        end;
      finally
        ButtonConvert.Enabled := True;
      end;
    end;
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    var GIF:  TGIFImage;
    begin
    GIF := TGIFImage.Create;
    GIF.LoadFromFile('L:\weiyan\我的程序\图片图形\db01.gif');
    Image1.Picture.Assign(gif);GIF.FREE;
    end;
    end.