Gif Animation in Delphi FMX

Recently my wife asked me to help with an urgent request: a simple animation for a family dinner presentation. It was to be the last slide of the night, to cheer everyone up.

She had two animated gifs, the first from Quentin Tarantino’s famous Pulp Fiction dance scene, and another of an unknown origin. The plan was to overlay the heads with pictures of her parents and their grand children, then add an upbeat soundtrack.

The first issue was, how to play an animated Gif in FMX. A StackOverflow answer led me to TGifPlayer. Playing the animated gif couldn’t be simpler, you associate the player with an image, load the gif from file, and instruct the player to play.

FGifPlayer := TGifPlayer.Create(Self);
FGifPlayer.Image := imgGrandParents;
FGifPlayer.LoadFromFile('Images\PulpFiction.gif');
FGifPlayer.Play;

Frames

I used two frames, one for each animated gif. On each frame the head of each person was overlayed ontop of an animated gif head:

heads

Each frame had a timer to co-ordinate the rotation of the head, the code couldn’t be simpler, for example rotating the grand parents:

procedure TAhGongAhMaFrame.OnTick;
const
  LastAngle=3;

  AhGongAngles: array[0..LastAngle] of integer = (15,0,-15,0);
  AhMaAngles: array[0..LastAngle] of integer = (15,0,-15,0);
begin
  Inc(FCounter);
  if FCounter>LastAngle then FCounter:=0;

  imgAhGong.RotationAngle := AhGongAngles[FCounter];
  imgAhMa.RotationAngle := AhMaAngles[FCounter];
end;

Finishing Up

I then recorded the animation with Obs and used Windows Movie Maker to add fading effects, and a sound track. Thanks to the excellent TGifPlayer, and FMX, this was a very simple and timely task.

6 thoughts on “Gif Animation in Delphi FMX

    1. Hi Lelie, can you check your privacy settings perhaps? The video plays fine for me, and I just confirmed my friend can see it too. If you don’t mind me asking, which browser are you using?

      Like

    1. This is standard WordPress functionality though, so I’m not sure what the issue might be, it must be client/configuration related.

      It’s working fine for me in FireFox, and Chrome, on Windows and Linux. I’ll try Mac next.

      Thanks for the update, I’ll see if I can find what might be wrong.

      Which version of FireFox are you using, and what Operating System?

      Like

Leave a Reply to csvelocity Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s