在DELPHI中显示GIF动画


想没想过在DELPHI中显示GIF动画?Delphi的用户是非常幸运的,因为有免费控件可以使用。最著名的控件是Anders Melander编写的TGifImage,并提供完整的源程序。它原来的主页是www.melander.dk/delphi/gifimage/,不过有很长时间没有更新了。如果要在新版本的Delphi中使用,可以从http://finn.mobilixnet.dk/delphi/下载Finn Tolderlund改写的Delphi 5/6/7版本的TGifImage。 现在看看怎么在DELPHI中使用GIFImage.pas文件,显示GIF动画首先,新建一个工程,在Project-OPTIONS菜单中的Directories/Conditionals页中的search中添加一个路径,这个路径指向GIFImage.pas所在文件夹然后在FORM1的PUBLIC区添加一个变量GIF,定义为TGIFImage类型在form1的onCreate中添加代码:GIF := TGIFImage.Create; 在form1上添加一个按钮button1,添加一个image控件在button1的click事件中添加代码: Gif.LoadFromFile('d:\abc.gif'); GIF.Paint(Image1.Canvas,Image1.ClientRect,[goAsync,goLoop,goAnimate]);



unit Unit1;

interface

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

type
TForm1 = class(TForm)
Image1: TImage;
Timer1: TTimer;
Panel1: TPanel;
Image2: TImage;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
i:integer;
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
gif:TGIFImage;
gif1:TGIFImage;
begin
//include(GIFImageDefaultDrawOptions, goDirectDraw);
gif:=TGIFImage.Create;
gif1:=TGIFImage.Create;
gif.LoadFromFile('test.gif');
gif1.LoadFromFile('test.gif');
try
GIF.Paint(Image1.Canvas,Image1.ClientRect,[goTransparent,goDither,goAsync,goLoop,goAnimate,goDirectDraw]);
GIF1.Paint(Image2.Canvas,Image2.ClientRect,[goTransparent,goAsync,goLoop,goAnimate]);

//Image1.Picture.Assign(gif);
//include(GIFImageDefaultDrawOptions, goDirectDraw);
//Image2.Picture.Assign(gif1);
finally
//GIF.Free;
//gif1.Free;
end;

end;

procedure TForm1.Timer1Timer(Sender: TObject);

begin
//gif.PaintStart;
//image1.Picture.Assign(gif.Bitmap);
//Image1.Repaint;
// if (i<(gif.Images.Count-1)) then Inc(i) else i:=0;

end;

end.


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/swei315/archive/2010/04/13/5483027.aspx
联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678