Animated GIF in Firemonkey

风流意气都作罢 提交于 2019-12-01 05:29:23

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11870944/animated-gif-in-firemonkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!