Recent

Author Topic: Animated GIF's and Lazarus IDE  (Read 1993 times)

Aruna

  • Hero Member
  • *****
  • Posts: 568
Animated GIF's and Lazarus IDE
« on: December 13, 2024, 03:22:47 am »
Hello everyone, I’m trying to display an animated GIF on a form in the Lazarus IDE. What would be the best approach to achieve this? Do we have a component that I could load with the separate images of the gif animation and then run it through code? OR a component that supports animated gifs natively?

dsiders

  • Hero Member
  • *****
  • Posts: 1324
Re: Animated GIF's and Lazarus IDE
« Reply #1 on: December 13, 2024, 06:18:37 am »
Hello everyone, I’m trying to display an animated GIF on a form in the Lazarus IDE. What would be the best approach to achieve this? Do we have a component that I could load with the separate images of the gif animation and then run it through code? OR a component that supports animated gifs natively?

Use the Forum search option. Plenty of discussions and suggestions there.
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

Khrys

  • Full Member
  • ***
  • Posts: 128
Re: Animated GIF's and Lazarus IDE
« Reply #2 on: December 13, 2024, 06:49:15 am »
BGRAControls has  TBGRASpriteAnimation, and together with BGRABitmap's  TBGRAAnimatedGif  it is possible to load and display animated GIFs.

Example copied verbatim from a project where I display an animated logo on a loading screen (comments give important context):

Code: Pascal  [Select][+][-]
  1. procedure TFormMain.FormCreate(__Sender: TObject);
  2. var
  3.   AnimFrames: TBGRAAnimatedGif;
  4. begin
  5.   AnimFrames := TBGRAAnimatedGif.Create(); // Lazarus doesn't allow direct embedding of .gif files and will instead...
  6.   AnimFrames.LoadFromResource('LOGO_LOADING'); // ...decompress all frames at design-time, which is suboptimal
  7.   SpriteAnimationLoading.GifImageToSprite(AnimFrames); // (+0.7 s startup time vs. +25 MiB file size)
  8.   SpriteAnimationLoading.AnimSpeed := AnimFrames.FrameDelayMs[0]; // Without this line the frame rate is too low (why?)
  9.   AnimFrames.Free();
  10. end;

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Animated GIF's and Lazarus IDE
« Reply #3 on: December 13, 2024, 01:44:19 pm »
Hello everyone, I’m trying to display an animated GIF on a form in the Lazarus IDE. What would be the best approach to achieve this? Do we have a component that I could load with the separate images of the gif animation and then run it through code? OR a component that supports animated gifs natively?

Use the Forum search option. Plenty of discussions and suggestions there.
Thank you I already did before asking sadly could not find anything that meets my requirements.

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Animated GIF's and Lazarus IDE
« Reply #4 on: December 13, 2024, 01:52:13 pm »
BGRAControls has  TBGRASpriteAnimation, and together with BGRABitmap's  TBGRAAnimatedGif  it is possible to load and display animated GIFs.

Example copied verbatim from a project where I display an animated logo on a loading screen (comments give important context):

Code: Pascal  [Select][+][-]
  1. procedure TFormMain.FormCreate(__Sender: TObject);
  2. var
  3.   AnimFrames: TBGRAAnimatedGif;
  4. begin
  5.   AnimFrames := TBGRAAnimatedGif.Create(); // Lazarus doesn't allow direct embedding of .gif files and will instead...
  6.   AnimFrames.LoadFromResource('LOGO_LOADING'); // ...decompress all frames at design-time, which is suboptimal
  7.   SpriteAnimationLoading.GifImageToSprite(AnimFrames); // (+0.7 s startup time vs. +25 MiB file size)
  8.   SpriteAnimationLoading.AnimSpeed := AnimFrames.FrameDelayMs[0]; // Without this line the frame rate is too low (why?)
  9.   AnimFrames.Free();
  10. end;
Thank you for this code snippet but after reading the comments I feel the delay will make what I want to do nearly impossible. Here is a link to a a zip file that has the source of a demo game I am putting together using Lazarus IDE and FPC. The request for an animated gif-supported component was to try and simulate an explosion when a bullet collides with an enemy. I will try your code and see though... any suggestions after having a look at the attached zip would be very welcome.

cdbc

  • Hero Member
  • *****
  • Posts: 1771
    • http://www.cdbc.dk
Re: Animated GIF's and Lazarus IDE
« Reply #5 on: December 13, 2024, 02:37:30 pm »
Hi
Just a thought...
Why don't you ask how they'd do it, in the 'Castle-Game-Engine' forum, just give them the last explanation from reply #4 in this thread...
They're friends of our forum and Michalis is himself a member here  ;)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

mav

  • Jr. Member
  • **
  • Posts: 83
Re: Animated GIF's and Lazarus IDE
« Reply #6 on: December 13, 2024, 02:38:21 pm »
I'm using a component made by someone called Escafandra...it works pretty well for me.
I've made an example of how it's used:

lainz

  • Hero Member
  • *****
  • Posts: 4659
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Animated GIF's and Lazarus IDE
« Reply #7 on: December 13, 2024, 03:11:11 pm »
with bgrabitmao you can draw the gif according to your own timer... just load into memory the gif first so it's loading time is not a problem.

or use a game dedicated tool better...

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Animated GIF's and Lazarus IDE
« Reply #8 on: December 14, 2024, 05:41:37 am »
Hi
Just a thought...
Why don't you ask how they'd do it, in the 'Castle-Game-Engine' forum, just give them the last explanation from reply #4 in this thread...
They're friends of our forum and Michalis is himself a member here  ;)
Regards Benny
Hi Benny, I did think about asking in the 'Castle-Game-Engine' forum but then I thought since I am not using their engine they may wonder why I am asking a question that has nothing to do with 'Castle-Game-Engine' ? I will ask them and see what they say. Thank you.

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Animated GIF's and Lazarus IDE
« Reply #9 on: December 14, 2024, 05:43:21 am »
I'm using a component made by someone called Escafandra...it works pretty well for me.
I've made an example of how it's used:
Thank you very much @mav I will test your example when I wake up in the morning it has been a rather long tiring day I am too tired to test right away.

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Animated GIF's and Lazarus IDE
« Reply #10 on: December 14, 2024, 05:44:42 am »
with bgrabitmao you can draw the gif according to your own timer... just load into memory the gif first so it's loading time is not a problem.

or use a game dedicated tool better...
Thank you @lainz I will look into bgrabitmao and I want to do this without using a game-engine.

lainz

  • Hero Member
  • *****
  • Posts: 4659
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Animated GIF's and Lazarus IDE
« Reply #11 on: December 14, 2024, 08:43:39 pm »
A typo: is bgrabitmap not bgrabitmao  :[ sorry

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Animated GIF's and Lazarus IDE
« Reply #12 on: December 14, 2024, 09:30:08 pm »
I'm using a component made by someone called Escafandra...it works pretty well for me.
I've made an example of how it's used:
It seems the component was designed for Windows and I am running Linux Debian. Please see attached screenshot.

Aruna

  • Hero Member
  • *****
  • Posts: 568
Re: Animated GIF's and Lazarus IDE
« Reply #13 on: December 14, 2024, 09:31:37 pm »
A typo: is bgrabitmap not bgrabitmao  :[ sorry
I figured no worries it is all good :)

szlbz

  • New Member
  • *
  • Posts: 43
Re: Animated GIF's and Lazarus IDE
« Reply #14 on: December 15, 2024, 02:55:00 am »
I'm using a component made by someone called Escafandra...it works pretty well for me.
I've made an example of how it's used:
It seems the component was designed for Windows and I am running Linux Debian. Please see attached screenshot.
I have modified it to Linux/Windows version

 

TinyPortal © 2005-2018