25

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.

Vitim.us
  • 16,145
  • 12
  • 81
  • 96

3 Answers3

54

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.

David Heffernan
  • 572,264
  • 40
  • 974
  • 1,389
  • 3
    Beware the shit-show called Jedi VCL which will prevent loading animated GIFs into a TImage if it's registered. – Warren P Nov 08 '17 at 22:24
  • 1
    @WarrenP I wondered why this approach no longer works... How to disable it? I tried the following but couldn't find a solution. (1) I have already disabled the 'Register global design editors' option when installing JVCL. (2) The Project Jedi branch of the IDE options window doesn't have related settings. (3), I couldn't figure out which of the installed JEDI packages might contain this feature, see https://ibb.co/sQ6b1CV – Edwin Yip Feb 26 '19 at 06:08
  • 1
    Also disabled the 'JvGif for .gif' checkbox of the JVCL installer, let the installer rebuilt the packages, but issue still exits. – Edwin Yip Feb 26 '19 at 06:28
  • 1
    Update: **working solution**: Disabled the JvMM packages when installing JVCL. If you can't do that, comment out the following line from JvMMReg.pas: `RegisterPropertyEditor(TypeInfo(TJvGIFImage), nil, '', TJvGraphicPropertyEditor);` – Edwin Yip Feb 26 '19 at 07:10
10

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 :)

kleopatra
  • 49,346
  • 26
  • 88
  • 189
steve
  • 109
  • 1
  • 2
  • 2
    DoubleBuffered := True is usually a bad move – David Heffernan Feb 15 '15 at 20:55
  • Excellent code my dear friend. Shows me that flicker doesn't happen at all when you use the above code in a form which has no other control except the TImage. +1 for a flicker free experience. – user30478 Dec 17 '18 at 13:12
  • I know this is an old thread, but it may be a good idea to stop it when the form is not in focus to save resources. – Vitim.us Oct 27 '20 at 14:54
5

Searched Google for 'Delphi Gif' Came up with this

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

now part of Delphi

Toby Allen
  • 10,562
  • 10
  • 70
  • 120