5

I'm trying to display an animated GIF in a Firemonkey HD form using TImage but I do not see any methods for animation.

Using Vcl.Imaging.gifImg is not an option because types differ.

Can someone suggest a way to solve this problem or probably component to animate GIF images under Firemonkey?

The only way I find for now is:

  1. create TGIFImage instance and load the GIF image

  2. loop through gif.images:

    a. save current image to stream

    b. Image1.bitmap.loadFromStream [Image1 is FMX:TImage]

Is there any smarter solution?

TLama
  • 75,147
  • 17
  • 214
  • 392
iPath ツ
  • 2,468
  • 20
  • 31
  • if you would make imaging in a background thread, then the solution might be not that dumb as u think. Even if FMX had it natively - it still and it done exactly that way - via frame switching by background thread. otl.17slon.com might make threading a bit easier – Arioch 'The Aug 09 '12 at 14:23
  • u can also look at Vampyre Imaging library, it clais FMX support in Mercurial (but obviously not in releases made in 2009). However probably you would still implement frame switching worker thread. But i don't know. – Arioch 'The Aug 09 '12 at 14:25
  • 1
    Arioch 'The: isn't TTimer better and easier choice than using threads? They both end up in the app's message queue. Also one thread per GIF would be resource consuming... – iPath ツ Aug 10 '12 at 00:39
  • i don't know if timer would make smooth animation but surely u can try it. And i'd not use intermediate stream but rather just pre-unpacked array of bitmaps – Arioch 'The Aug 10 '12 at 09:00
  • 1
    @Arioch, the main problem is the bitmap. iPath is using VCL class in FMX environment and classes like `TBitmap` or `TCanvas` are not compatible. That's the reason of the stream usage; otherwise you would be able to use classes like `TGIFImage` or `TGIFRenderer` directly. And `TTimer` is prefectly sufficient for animations. If you'd use worker thread then you would have to synchronize UI with each frame rendering and that would, as iPath correctly said, enqueue messages into the UI main thread's message queue. Even `TGIFRenderer` itself uses timer, not a thread for rendering loop ;-) – TLama Aug 11 '12 at 12:34
  • Why downvoting on this question? – iPath ツ Sep 21 '14 at 22:27

1 Answers1

5

You can use TBitmapListAnimation with a single image which has each frame of the animation inside a long strip. eg, if your animation has 4 frames and is 32px by 32px then you need to create an image 128px wide by 32px high and add each frame side by side...

Then add a TImage to the form (you don't have to load a bitmap into this)

Add a TBitmapListAnimation with the TImage as it's parent

Double click AnimationBitmap and load your animation image strip

Drop down PropertyName and pick Bitmap

Set AnimationCount to 4 and AnimationRowCount 1 for this example

Set enabled to true

TBitmapListAnimation has good control over animation frame rates, reversing, looping and interpolation. I couldn't find a way to get a .gif to animate in FireMonkey2 but if you have the means to convert an animated .gif into a 'cartoon strip' then this is a good way to do animations.

PS This is Delphi XE3...so can't say if these components existed in previous version.

sergeantKK
  • 644
  • 7
  • 16
  • 1
    I believe this is how the `TAniIndicator` in XE3 works. The correct term for "cartoon strip" would be sprites or sprite list. :) – Scott P Nov 17 '12 at 21:46