Forum > General

Animated GIF's and Lazarus IDE

(1/4) > >>

Aruna:
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:

--- Quote from: Aruna 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?

--- End quote ---

Use the Forum search option. Plenty of discussions and suggestions there.

Khrys:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TFormMain.FormCreate(__Sender: TObject);var  AnimFrames: TBGRAAnimatedGif;begin  AnimFrames := TBGRAAnimatedGif.Create(); // Lazarus doesn't allow direct embedding of .gif files and will instead...  AnimFrames.LoadFromResource('LOGO_LOADING'); // ...decompress all frames at design-time, which is suboptimal  SpriteAnimationLoading.GifImageToSprite(AnimFrames); // (+0.7 s startup time vs. +25 MiB file size)  SpriteAnimationLoading.AnimSpeed := AnimFrames.FrameDelayMs[0]; // Without this line the frame rate is too low (why?)  AnimFrames.Free();end;

Aruna:

--- Quote from: dsiders on December 13, 2024, 06:18:37 am ---
--- Quote from: Aruna 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?

--- End quote ---

Use the Forum search option. Plenty of discussions and suggestions there.

--- End quote ---
Thank you I already did before asking sadly could not find anything that meets my requirements.

Aruna:

--- Quote from: Khrys 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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TFormMain.FormCreate(__Sender: TObject);var  AnimFrames: TBGRAAnimatedGif;begin  AnimFrames := TBGRAAnimatedGif.Create(); // Lazarus doesn't allow direct embedding of .gif files and will instead...  AnimFrames.LoadFromResource('LOGO_LOADING'); // ...decompress all frames at design-time, which is suboptimal  SpriteAnimationLoading.GifImageToSprite(AnimFrames); // (+0.7 s startup time vs. +25 MiB file size)  SpriteAnimationLoading.AnimSpeed := AnimFrames.FrameDelayMs[0]; // Without this line the frame rate is too low (why?)  AnimFrames.Free();end;
--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

Go to full version