Recent

Author Topic: BGRABitmap GIF animation save error  (Read 918 times)

shock

  • Newbie
  • Posts: 2
BGRABitmap GIF animation save error
« on: November 24, 2024, 09:21:03 am »
I have been trying to create a GIF animation using BGRABitmap.  I have no trouble creating each frame (24-bit colour plus transparency) as a TBGRABitmap object.  I run a simple loop to generate each frame, then call AddFullFrame to add each frame to a TBGRAAnimatedGif object.  I get an Access Violation error message when writing the animation to disk ('animation.gif'), though a file is created but with only the first frame in it.  If I change the file type to APNG ('animation.apng') the file is written correctly with all frames in the file.

        image := TBGRABitmap.Create(1920, 1028, BGRAPixelTransparent);
        animation := TBGRAAnimationGif.Create;
        animation.SetSize(image.Width, image.Height);
        for i := 1 to n_frames
          do begin
            generate_frame(i, image);
            animation.AddFullFrame(image);
          end;
        animation.SaveToFile('animation.gif');

When writing a single GIF image I find I have to use TRGBAColorQuantizer to reduce the colour depth to 256 before saving the image.  I have tried doing the same for each image before passing to AddFullFrame but I still get the Access Violation.

            q := TBGRAColorQuantizer.Create(image, acIgnore, 256);
            dithered := q.GetDitheredBitmap(daFloydSteinberg, image);
            animation.AddFullFrame(dithered);
            q.Free;

I have looked through the BGRABitmap sources but can find nothing obvious that would cause this error.

Any help to track this down will be appreciated.  Thank you.

Handoko

  • Hero Member
  • *****
  • Posts: 5382
  • My goal: build my own game engine using Lazarus
Re: BGRABitmap GIF animation save error
« Reply #1 on: November 25, 2024, 02:23:51 pm »
Can you provide the whole source code? It will be much easier for us to help you if we have the compile-able source code, so we can run, inspect and find where you did it wrong.

Copy all the source files into a new folder but excluding the binary (exe file), *.bak, lib and backup folders. Compress the folder and sent the zip file to the forum.

 

TinyPortal © 2005-2018