在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所在文件夹然后在FORM1PUBLIC区添加一个变量GIF,定义为TGIFImage类型在form1onCreate中添加代码:GIF := TGIFImage.Create; form1上添加一个按钮button1,添加一个image控件在button1click事件中添加代码: 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.

转载于:https://www.cnblogs.com/blogpro/p/11426595.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
delphi 7 gif控件 unit GIFImage; //////////////////////////////////////////////////////////////////////////////// // // // Project: GIF Graphics Object // // Module: gifimage // // Description: TGraphic implementation of the GIF89a graphics format // // Version: 2.2 // // Release: 5 // // Date: 23-MAY-1999 // // Target: Win32, Delphi 2, 3, 4 & 5, C++ Builder 3 & 4 // // Author(s): anme: Anders Melander, [email protected] // // fila: Filip Larsen // // rps: Reinier Sterkenburg // // Copyright: (c) 1997-99 Anders Melander. // // All rights reserved. // // Formatting: 2 space indent, 8 space tabs, 80 columns. // // // //////////////////////////////////////////////////////////////////////////////// // Changed 2001.07.23 by Finn Tolderlund: // // Changed according to e-mail from "Rolf Frei" // // on 2001.07.23 so that it works in Delphi 6. // // // // Changed 2002.07.07 by Finn Tolderlund: // // Incorporated additional modifications by Alexey Barkovoy ([email protected]) // found in his Delphi 6 GifImage.pas (from 22-Dec-2001). // // Alexey Barkovoy's Delphi 6 gifimage.pas can be downloaded from // // http://clootie.narod.ru/delphi/download_vcl.html // // These changes made showing of animated gif files more stable. The code // // from 2001.07.23 could crash sometimes with an Execption EAccessViolation. // // // // Changed 2002.10.06 by Finn Tolderlund: // // Delphi 7 compatible. // // // // Changed 2003-03-06 by Finn Tolderlund: // // Changes made as a result of postings in borland.public.delphi.graphics // // from 2003-02-28 to 2003-03-05 where white (255,255,255) in a bitmap // // was converted to (254,254,254) in the gif. // // The doCreateOptimizedPaletteFromSingleBitmap function and // // the CreateOptimizedPaletteFromManyBitmaps function is changed so that // // the correct offset 246 is used instead of 245. // // The ReduceColors function is changed according to Anders Melander's post // // so that a colour get converted to the precise colour if that colour is // // present in the palette when using ColorReduction rmQuantize. // // // // Changed 2003-03-09 by Finn Tolderlund: // // Delphi 7 version is now assumed if unknown compiler version is unknown // // for better compatibility with future Delphi versions. // // Hopefully this code is now compatible with future Delphi versions, // // unless Borland makes some changes that breaks existing code. // // // // Changed 2003-08-04 by Finn Tolderlund: // // Changed procedure AddMaskOnly so that it doesn't leak a GDI HBitmap-object // // and it doesn't release the handle of the source bitmap which // // is used to assign to the GIF object as in gif.assign(bm); // // These changes were made as a result of a news post made by Renate Schaaf // // with the subject "TGifImage HBitmap leak on assign?" // // in borland.public.delphi.graphics on Mon 28 Jul 2003 and Sun 03 Aug 2003. // // // // Changed 2004.03.09 by Finn Tolderlund: // // Added a ForceFrame property to the TGIFImage class. // // The ForceFrame property can be used to make TGIFImage display a apecific // // sub frame from an animated gif. // // How to use: Set the Animate property to False and set the ForceFrame // // property to a desired frame number (0-N) // // Normal display: Set the ForceFrame property to -1 and set Animate to True. // // If ForceFrame is negative TGIFImage behaves just as before this change. // // Note that if the sub frame in the gif only contains part of the image // // (i.e. only the changes from previous frames) the result is unpredictable. // // The result is best if each sub frame contains a whole image. // // If the sub frame is transparent the background is not automatically // // restored, you must do so yourself if you want that. // // If you are using a TImage to display the gif you can use // // Image.Parent.Invalidate or Image.Parent.Refresh to restore the background. // // This change was made as a result of a email correspondance with // // Tineke Kosmis (http://www.classe.nl/) which requested such a property. // // // //////////////////////////////////////////////////////////////////////////////// // // // Please read the "Conditions of use" in the release notes. // // // //////////////////////////////////////////////////////////////////////////////// // Known problems: // // * The combination of buffered, tiled and transparent draw will display the // background incorrectly (scaled). // If this is a problem for you, use non-buffered (goDirectDraw) drawing // instead. // // * The combination of non-buffered, transparent and stretched draw is // sometimes distorted with a pattern effect when the image is displayed // smaller than the real size (shrinked). // // * Buffered display flickers when TGIFImage is used by a transparent TImage // component. // This is a problem with TImage caused by the fact that TImage was designed // with static images in mind. Not much I can do about it. // //////////////////////////////////////////////////////////////////////////////// // To do (in rough order of priority): // { TODO -oanme -cFeature : TImage hook for destroy notification. } // { TODO -oanme -cFeature : TBitmap pool to limit resource consumption on Win95/98. } // { TODO -oanme -cImprovement : Make BitsPerPixel property writable. } // { TODO -oanme -cFeature : Visual GIF component. } // { TODO -oanme -cImprovement : Easier method to determine DrawPainter status. } // { TODO -oanme -cFeature : Import to 256+ color GIF. } // { TODO -oanme -cFeature : Make some of TGIFImage's properties persistent (DrawOptions etc). } // { TODO -oanme -cFeature : Add TGIFImage.Persistent property. Should save published properties in application extension when this options is set. } // { TODO -oanme -cBugFix : Solution for background buffering in scrollbox. }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值