如何调用RES文件里的gif图片!小弟万分感谢,在线等待。。

yangzong20 2011-02-18 05:14:08
我编译了一个RES文件其中把一个gif图片编译进去了,变量名为H2!现在我不知道如何在程序里面调用这个gif图片赋值给Image1控件(注明一点,我的Image1控件是支持gif图片的)。我知道如何调用bmp图片但我不知道如何调用gif图片,请高手指导,小弟万分感谢,在线等待。。
...全文
62 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kye_jufei 2011-02-19
  • 打赏
  • 举报
回复
[code=Delphi(Pascal]unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,GIFImage, StdCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
{$R sample.RES}

procedure TForm1.FormCreate(Sender: TObject);
var
Streams:TStream;
gif:TGIFImage;
begin
try
DeleteFile(PChar(ExtractFilePath(ParamStr(0))+'abc.gif'));
Streams:=TResourceStream.Create(hInstance,'Mygif','gif');
try
gif:=TGIFImage.Create;
try
gif.LoadFromStream(Streams);
Image1.Picture.Assign(gif);
finally
gif.Free;
end;
finally
Streams.Free;
end;
except
end;
end;[/code]
kye_jufei 2011-02-19
  • 打赏
  • 举报
回复
[code=Delphi(Pascal]unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,GIFImage, StdCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
{$R sample.RES}

procedure TForm1.FormCreate(Sender: TObject);
var
Streams:TStream;
gif:TGIFImage;
begin
try
DeleteFile(PChar(ExtractFilePath(ParamStr(0))+'abc.gif'));
Streams:=TResourceStream.Create(hInstance,'Mygif','gif');
try
gif:=TGIFImage.Create;
try
gif.LoadFromStream(Streams);
Image1.Picture.Assign(gif);
finally
gif.Free;
end;
finally
Streams.Free;
end;
except
end;
end;

end.[/code]
kye_jufei 2011-02-19
  • 打赏
  • 举报
回复
抽了點時間,給你寫了一個demo,測試過過:

資源文件定義如下:(abc.gif為gif圖片檔案)

[code=HTM]Mygif gif abc.gif[/code]

example:

[code=Delphi(Pascal]unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,GIFImage, StdCtrls;

type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
{$R sample.RES}

procedure TForm1.FormCreate(Sender: TObject);
var
Streams:TStream;
gif:TGIFImage;
begin
try
DeleteFile(PChar(ExtractFilePath(ParamStr(0))+'abc.gif'));
Streams:=TResourceStream.Create(hInstance,'Mygif','gif');
try
gif:=TGIFImage.Create;
try
gif.LoadFromStream(Streams);
Image1.Picture.Assign(gif);
finally
gif.Free;
end;
finally
Streams.Free;
end;
except
end;
end;

end.[/code]




贝隆 2011-02-19
  • 打赏
  • 举报
回复
我的印象中Res文件不支持GIF

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧