Victor
Victor

Reputation: 22208

How to use Animated Gif in a delphi form

I think theres no native support to gif animated images.

How is the best way? any free component that allow that? I was thinking in using a TImage and a ImageList + Timer, but I need to export each frame of the gif to a separated bmp file.

Upvotes: 27

Views: 68293

Answers (4)

yonojoy
yonojoy

Reputation: 5566

If you happen to use JVCL, like me, you will likely run into trouble with Davids answer, because JVCL registers TJvGifImage for GIF files which does not descent from TGifImage (see comments to Davids answer).

In this case the easiest solution seems to be loading the GIF file directly from resources:

//eg in FormCreate:
FAnimationGraphic := TGifImage.Create;
FAnimationGraphic.LoadFromResourceName(HInstance, 'GIF_XYZ_ANIMATION');
ImageAnimation.Picture.Graphic := FAnimationGraphic;

(ImageAnimation.Picture.Graphic as TGIFImage).Animate := True;

//eg in FormDestroy:
//FAnimationGraphic must be freed! 
//ImageAnimation.Picture is not owner of the image
FreeAndNil(FAnimationGraphic);

Upvotes: 0

steve
steve

Reputation: 129

this is simply loading an animated gif and not making one

procedure TForm1.FormCreate(Sender: TObject);

begin

  ( Image1.Picture.Graphic as TGIFImage ).Animate := True;// gets it goin'

  ( Image1.Picture.Graphic as TGIFImage ).AnimationSpeed:= 500;// adjust your speed

  Form1.DoubleBuffered := True;// stops flickering

end;

stackoverflow has helped me and so my little bit in return :)

Upvotes: 12

David Heffernan
David Heffernan

Reputation: 613572

It's pretty simple in modern Delphi. It's all built in. Drop a TImage onto the form and load the animated GIF into the Picture property. Then, start the animation by means of the Animate property:

(Image1.Picture.Graphic as TGIFImage).Animate := True;

You can control the animation with AnimateLoop and AnimateSpeed. It should be pretty easy to guess how to switch the animation off again!

Now, since you are using Delphi 7, you don't have the TGIFImage component built-in. However, you can download the code from Finn Tolderlund's website (you want the latest version of TGIFImage). With this version of the component, the code above should work fine, although I personally have not used it since I ported from D6 to D2010 a few years back.

All these various TGIFImage codes are really just versions of the same component, originally written by Anders Melander and, in 2007, donated to Embarcadero for inclusion in Delphi.

Upvotes: 57

Toby Allen
Toby Allen

Reputation: 11221

Searched Google for 'Delphi Gif' Came up with this

http://melander.dk/delphi/gifimage/

now part of Delphi

Upvotes: 5

Related Questions