Tweening of 2 Coloured Images: Now Saving Animated Gif (Yay) lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2024-09-01 06:44 Converted some Delphi code and added Endless Play back animation features. Loads only bmp and needs to be 24bit and same sized. Transparent pngs would be nice and make it so it can load other formats and make images same sized if loaded with different sizes. Also would like an export to animated gif or avi. Might need  to be convert from TImage to bgrabmp. Just added a save the displayed tween frame to png. ---------------------------------------------------------------------- paweld · 2024-09-01 09:01 Added BGRABitmap support: - support formats: bmp, png, jpg, gif - support for transparency - auto resizing second image Edited few minutes later: removed memory leaks ---------------------------------------------------------------------- Boleeman · 2024-09-01 09:36 Thanks for helping out Paweld. Ah I see you did some fixes. Was getting these errors. List out of bounds. Also not Tweening midway on some occassions. Also Reset not working. I will test your new update. I appreciate your help. Thanks. What I noticed after testing your fix: After loading the images and moving the trackbar I get the Tweening happening. If I click Create Sequence and then click either Show Tween or Show Seq Fwd Back Buttons the the tweening stops working until the very end. If I then click Reset and move the trackbar I get the Tweening happening again, but then I get a List Index (0) out of bounds error when I click either Show Tween or Show Seq Fwd Back Buttons. ---------------------------------------------------------------------- paweld · 2024-09-01 10:16 fixed ---------------------------------------------------------------------- Boleeman · 2024-09-01 10:31 Wow Paweld that last update works well. I tried fixing the errors but was going round in circles. Like how you made the frame number for the saved png. That is a good feature for saving to an animation. Paweld, I also tested two transparent pngs of 2 different sizes. The saved png was also saved transparently. Worked well. Success. Hooray ! Thanks Paweld for those great additions. ---------------------------------------------------------------------- Boleeman · 2024-09-01 11:06 Sorry to bother again. Was getting a Heap trace message after ending the program. Also the release version file size seems unusually large. Not sure why? ---------------------------------------------------------------------- paweld · 2024-09-01 11:11 Menu: Project > Project options, on options tree Compiler options > Debugging uncheck Use Heaptrc unit and Trash variables. I enabled this options to check mem leaks. ---------------------------------------------------------------------- Boleeman · 2024-09-02 07:35 Paweld, Yes that was it. Turn of Heap Trc and Trash Variable. Release exe file back to normal size and message gone. Thanks for your great help on this Tween program. Much appreciated Paweld. ---------------------------------------------------------------------- Boleeman · 2024-09-02 08:10 I tried saving to animated gif with this code but I get an access violation: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFormTween.btbMakeAnigifClick(Sender: TObject);var  GifImage: TBGRAAnimatedGif;  i: Integer;  Speed: Integer;  bmp: TBGRABitmap;  ResizedBmp: TBGRABitmap;  png: TPortableNetworkGraphic;  ms: TMemoryStream;begin   Speed := SpinEditDelay.Value;   GifImage := TBGRAAnimatedGif.Create;  try     GifImage.SetSize(ImageTween.Width, ImageTween.Height);    GifImage.LoopCount := 0;     for i := 0 to ImageSequence.Count - 1 do    begin      png := ImageSequence[i] as TPortableNetworkGraphic;      bmp := TBGRABitmap.Create;      try      ms := TMemoryStream.Create;        try          png.SaveToStream(ms); // Save PNG to memory stream          ms.Position := 0;          bmp.LoadFromStream(ms); // Load from memory stream to TBGRABitmap           // Resize bitmap if necessary        if (bmp.Width <> GifImage.Width) or (bmp.Height <> GifImage.Height) then          begin            ResizedBmp := bmp.Resample(GifImage.Width, GifImage.Height);            try            GifImage.AddFullFrame(ResizedBmp, Speed);            finally            ResizedBmp.Free;            end;          end          else        begin            GifImage.AddFullFrame(bmp, Speed);          end;        finally          ms.Free;        end;      finally        bmp.Free;      end;    end;     GifImage.OptimizeFrames;     if SaveDialog1.Execute then    begin      if SaveDialog1.FileName <> '' then      begin        GifImage.SaveToFile(ChangeFileExt(SaveDialog1.FileName, '.gif'));    end      else      begin        ShowMessage('No file name specified.');      end;    end;   finally    GifImage.Free;  end;end; ---------------------------------------------------------------------- circular · 2024-09-02 17:23 Hmm not sure why you would get an error. If you enabled debug info, what is the stack trace? ---------------------------------------------------------------------- Boleeman · 2024-09-03 11:03 Circular, Access violation solved: Missing BGRAColorQuantizerFactory := TBGRAColorQuantizer; Cannot believe it. I remembered from https://forum.lazarus.freepascal.org/index.php/topic,68394.0.html that I needed to add it because I was getting a similar Acess Violation error. The animated gif gets quite large if there are a lot of tween frames. I made a sample animated gif with only 3 frames (slowed down) due to file size limit of attachments. Takes a while to render the animated gif. Not sure why. Maybe TBGRAColorQuantizer ?