Recent

Author Topic: Tweening of 2 Coloured Images: Now Saving Animated Gif (Yay)  (Read 800 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 714
Tweening of 2 Coloured Images: Now Saving Animated Gif (Yay)
« on: September 01, 2024, 08:44:18 am »
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.
« Last Edit: September 03, 2024, 01:04:27 pm by Boleeman »

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: Tweening of 2 Coloured Images: extra features needed.
« Reply #1 on: September 01, 2024, 11:01:09 am »
Added BGRABitmap support:
- support formats: bmp, png, jpg, gif
- support for transparency
- auto resizing second image

Edited few minutes later: removed memory leaks
« Last Edit: September 01, 2024, 11:16:12 am by paweld »
Best regards / Pozdrawiam
paweld

Boleeman

  • Hero Member
  • *****
  • Posts: 714
Re: Tweening of 2 Coloured Images: extra features needed.
« Reply #2 on: September 01, 2024, 11:36:51 am »
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.
« Last Edit: September 01, 2024, 11:58:00 am by Boleeman »

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: Tweening of 2 Coloured Images: extra features needed.
« Reply #3 on: September 01, 2024, 12:16:22 pm »
fixed
Best regards / Pozdrawiam
paweld

Boleeman

  • Hero Member
  • *****
  • Posts: 714
Re: Tweening of 2 Coloured Images: extra features needed.
« Reply #4 on: September 01, 2024, 12:31:50 pm »
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.

« Last Edit: September 01, 2024, 12:53:33 pm by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 714
Re: Tweening of 2 Coloured Images: Extra features added by Paweld. Thanks.
« Reply #5 on: September 01, 2024, 01:06:33 pm »
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

  • Hero Member
  • *****
  • Posts: 1268
Re: Tweening of 2 Coloured Images: Extra features added by Paweld. Thanks.
« Reply #6 on: September 01, 2024, 01:11:46 pm »
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.
Best regards / Pozdrawiam
paweld

Boleeman

  • Hero Member
  • *****
  • Posts: 714
Re: Tweening of 2 Coloured Images: Extra features added by Paweld. Thanks.
« Reply #7 on: September 02, 2024, 09:35:28 am »
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

  • Hero Member
  • *****
  • Posts: 714
Re: Tweening of 2 Coloured Images: Extra features added by Paweld. Thanks.
« Reply #8 on: September 02, 2024, 10:10:44 am »
I tried saving to animated gif with this code but I get an access violation:

Code: Pascal  [Select][+][-]
  1. procedure TFormTween.btbMakeAnigifClick(Sender: TObject);
  2. var
  3.   GifImage: TBGRAAnimatedGif;
  4.   i: Integer;
  5.   Speed: Integer;
  6.   bmp: TBGRABitmap;
  7.   ResizedBmp: TBGRABitmap;
  8.   png: TPortableNetworkGraphic;
  9.   ms: TMemoryStream;
  10. begin
  11.  
  12.   Speed := SpinEditDelay.Value;
  13.  
  14.   GifImage := TBGRAAnimatedGif.Create;
  15.   try
  16.  
  17.     GifImage.SetSize(ImageTween.Width, ImageTween.Height);
  18.     GifImage.LoopCount := 0;
  19.  
  20.     for i := 0 to ImageSequence.Count - 1 do
  21.     begin
  22.       png := ImageSequence[i] as TPortableNetworkGraphic;
  23.       bmp := TBGRABitmap.Create;
  24.       try
  25.         ms := TMemoryStream.Create;
  26.         try
  27.           png.SaveToStream(ms); // Save PNG to memory stream
  28.           ms.Position := 0;
  29.           bmp.LoadFromStream(ms); // Load from memory stream to TBGRABitmap
  30.  
  31.           // Resize bitmap if necessary
  32.           if (bmp.Width <> GifImage.Width) or (bmp.Height <> GifImage.Height) then
  33.           begin
  34.             ResizedBmp := bmp.Resample(GifImage.Width, GifImage.Height);
  35.             try
  36.               GifImage.AddFullFrame(ResizedBmp, Speed);
  37.             finally
  38.               ResizedBmp.Free;
  39.             end;
  40.           end
  41.           else
  42.           begin
  43.             GifImage.AddFullFrame(bmp, Speed);
  44.           end;
  45.         finally
  46.           ms.Free;
  47.         end;
  48.       finally
  49.         bmp.Free;
  50.       end;
  51.     end;
  52.  
  53.     GifImage.OptimizeFrames;
  54.  
  55.     if SaveDialog1.Execute then
  56.     begin
  57.       if SaveDialog1.FileName <> '' then
  58.       begin
  59.         GifImage.SaveToFile(ChangeFileExt(SaveDialog1.FileName, '.gif'));
  60.       end
  61.       else
  62.       begin
  63.         ShowMessage('No file name specified.');
  64.       end;
  65.     end;
  66.  
  67.   finally
  68.     GifImage.Free;
  69.   end;
  70. end;  
« Last Edit: September 02, 2024, 04:16:10 pm by Boleeman »

circular

  • Hero Member
  • *****
  • Posts: 4356
    • Personal webpage
Re: Tweening of 2 Coloured Images: Save Animated Gif Problems.
« Reply #9 on: September 02, 2024, 07:23:56 pm »
Hmm not sure why you would get an error. If you enabled debug info, what is the stack trace?
Conscience is the debugger of the mind

Boleeman

  • Hero Member
  • *****
  • Posts: 714
Re: Tweening of 2 Coloured Images: Save Animated Gif Problems.
« Reply #10 on: September 03, 2024, 01:03:44 pm »
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 ?
« Last Edit: September 03, 2024, 01:11:29 pm by Boleeman »

 

TinyPortal © 2005-2018