Jump to content
Felix.

Create an animated gif from a set of bitmaps?

Recommended Posts

Subject says it all. How to create an animated gif from a set of bitmaps? (Firemonkey)

 

Thank you

Share this post


Link to post
1 hour ago, Remy Lebeau said:

AFAIK FireMonkey doesn't support animated GIFs.  Use an 3rd party image library that does.

Doesn't TGIFImage (the non-visual part) work with FireMonkey?

Share this post


Link to post
5 hours ago, Remy Lebeau said:

AFAIK FireMonkey doesn't support animated GIFs.  Use an 3rd party image library that does.

I don't need to view or play GIFs. I just need to create an animated GIF from a set of bitmaps.

Share this post


Link to post
5 hours ago, Felix. said:

I don't need to view or play GIFs. I just need to create an animated GIF from a set of bitmaps.

Try this:

procedure MakeGIF(Bitmap1, Bitmap2, Bitmap3: TBitmap);
var
  GIF: TGIFImage;
  Frame: TGIFFrame;
  GCExt: TGIFGraphicControlExtension;
  LoopExt: TGIFAppExtNSLoop;
begin
  GIF := TGIFImage.Create;
  try
  
    Frame := GIF.Add(Bitmap1);
    // Netscape Loop extension must be the first extension in the first frame!
    LoopExt := TGIFAppExtNSLoop.Create(Frame);
    LoopExt.Loops := 0; // Number of loops (0 = forever)

    // Add Graphic Control Extension
    GCExt := TGIFGraphicControlExtension.Create(Frame);
    GCExt.Delay := 30; // Animation delay (30 = 300 mS)
 
    Frame := GIF.Add(Bitmap2);
    GCExt := TGIFGraphicControlExtension.Create(Frame);
    GCExt.Delay := 30;

    Frame := GIF.Add(Bitmap3);
    GCExt := TGIFGraphicControlExtension.Create(Frame);
    GCExt.Delay := 30;

    GIF.OptimizeColorMap;
    GIF.Optimize([ooMerge, ooCrop], rmNone, dmNearest, 0);

    GIF.SaveToFile('foobar.gif');
  finally
    GIF.Free;
  end;
end;

This is just from (my) memory so I'm not sure if it compiles. It's been a while since I wrote that thing.

You should be able to find plenty of examples if you search for TGIFImage.

Share this post


Link to post
2 hours ago, Anders Melander said:

Try this:

This is just from (my) memory so I'm not sure if it compiles. It's been a while since I wrote that thing.

You should be able to find plenty of examples if you search for TGIFImage.

Thank you, your memory is great.

I'll try it today

Share this post


Link to post
17 hours ago, Anders Melander said:

Doesn't TGIFImage (the non-visual part) work with FireMonkey?

TGIFImage is a VCL class, AFAIK it is not available in FMX.  Also, as I don't use FMX myself, my claim about its lack of support for animated GIFs is mainly based on the below post, which presents some 3rd party solutions for displaying animated GIFs in an FMX UI:

 

https://stackoverflow.com/questions/45285599/how-to-use-animated-gif-in-firemonkey

 

For displaying a series of bitmaps in a UI, one can use TBitmapListAnimation, but I don't know if that can also be used to create a GIF.  Embarcadero's documentation only mentions that FMX's TBitmap supports GIF on all platforms except iOS, but doesn't mention what kinds of GIFs are supported.

Edited by Remy Lebeau

Share this post


Link to post

Ah yes, TGraphic is a VCL class. I forgot that.

 

I don't use FMX either and I knew FMX couldn't use TGIFImage for display (since that requires TPicture/TImage) but I would have thought one could still use the non-visual stuff such as load/save and GIF manipulation. I guess not.

Share this post


Link to post
On 12/23/2021 at 3:22 AM, Remy Lebeau said:

AFAIK FireMonkey doesn't support animated GIFs.  Use an 3rd party image library that does.

Which one would you recommend for Firemonkey?

Share this post


Link to post

This question was very old.
I had almost the same question, but I didn't want to make a gif file, this vedeo is good

 

 

Maybe it will help someone.
It doesn't work for me.

Because I want to know which frame is displayed at any moment.

Share this post


Link to post

Additional info: On RAD 12 it is possible to encode animated WebP (better format than GIF). See DocWiki.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×