Recent

Author Topic: Save GIF using BGRASpriteAnimation  (Read 850 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1171
    • Pixelink Software
Save GIF using BGRASpriteAnimation
« on: October 15, 2019, 09:04:09 pm »
I am trying to save a GIF from the BGRASpriteAnimation control
Is there a way to do it?
« Last Edit: October 15, 2019, 09:24:49 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Software
VB.NET 2019 • LAZ 2.02 •  Win10 • 16G RAM • Nivida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1171
    • Pixelink Software
Re: Save GIF using BGRASpriteAnimation
« Reply #1 on: October 15, 2019, 10:07:02 pm »
If there is no easier way to do this
then I was thinking this

If somehow, using the animated code Lainz provided last week.
If somehow, I could capture the current frame (going through all frames 1-by-1) in the animated Sprite control
store it as a bitmap in an array
and then put it back together and save it out to a gif file

This would be much more work, but it may be possible

What do you think?


« Last Edit: October 15, 2019, 10:09:14 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Software
VB.NET 2019 • LAZ 2.02 •  Win10 • 16G RAM • Nivida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 3270
    • Lainz
Re: Save GIF using BGRASpriteAnimation
« Reply #2 on: October 16, 2019, 02:04:05 am »
Is not hard, the sprite is a lot of bitmaps joined.

To get a frame multiply the width of the frame by the index of the frame.

Like width = 100, height = 100

Left = 100 (width) * 0 (index) = 0 <-- it gives you the left position from where start grabbing the frame
The rigth side is Left + Width, in this case 0 + 100

For index 10
100 * 10

You don't need to store everything in a temporary array. You can get the frame and then save it into the GIF, then get another frame and save it too. When all frames are done, just save the file.
« Last Edit: October 16, 2019, 03:20:39 am by lainz »

pixelink

  • Hero Member
  • *****
  • Posts: 1171
    • Pixelink Software
Re: Save GIF using BGRASpriteAnimation
« Reply #3 on: October 16, 2019, 02:19:22 pm »
Ah.. okay, I see what you are saying

Will give it a try.

Thanks
Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Software
VB.NET 2019 • LAZ 2.02 •  Win10 • 16G RAM • Nivida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 3270
    • Lainz
Re: Save GIF using BGRASpriteAnimation
« Reply #4 on: October 17, 2019, 02:18:11 am »
Tell me if you get success, if not we can try to include such functionality in the BGRASpriteAnimation.

The thing is I don't know for what will be usefull?

Edit: anyways, Ive opened an Issue on GitHub to add that functionality

Edit 2: Done on dev-branch of BGRAControls.
« Last Edit: October 17, 2019, 04:57:52 am by lainz »

pixelink

  • Hero Member
  • *****
  • Posts: 1171
    • Pixelink Software
Re: Save GIF using BGRASpriteAnimation
« Reply #5 on: October 17, 2019, 05:48:51 pm »
Tell me if you get success, if not we can try to include such functionality in the BGRASpriteAnimation.

The thing is I don't know for what will be usefull?

Edit: anyways, Ive opened an Issue on GitHub to add that functionality

Edit 2: Done on dev-branch of BGRAControls.

Okay... i will let you know.
Ha, I may even need some help. But I am going to try to do it with code first

Below is an app I am making
Loads a sprite sheet
Plays in SpriteAnimation control
Then, I can export it as an animated GIF

Well, at least that is my goal.
Eventually, I even want to use FFMpeg to exprt to video.

Can't Type - Forgetful - Had Stroke = Forgive this old man!

Pixelink Software
VB.NET 2019 • LAZ 2.02 •  Win10 • 16G RAM • Nivida GForce RTX 2060

lainz

  • Hero Member
  • *****
  • Posts: 3270
    • Lainz
Re: Save GIF using BGRASpriteAnimation
« Reply #6 on: October 18, 2019, 01:51:13 am »
Cool. Here are the methods you requested:
https://github.com/bgrabitmap/bgracontrols/commit/73406a9f512c9e4d20e3b38fdd926ebc81a3aeaa

Code: Pascal  [Select]
  1. procedure TBGRASpriteAnimation.LoadFromBGRABitmap(const BGRA: TBGRABitmap);
  2. begin
  3.   FSprite.Width := BGRA.Width;
  4.   FSprite.Height := BGRA.Height;
  5.   BGRA.Draw(FSprite.Canvas, 0, 0, False);
  6. end;
  7.  
  8. procedure TBGRASpriteAnimation.SpriteToAnimatedGif(Filename: string);
  9. var
  10.   i: integer;
  11.   gif : TBGRAAnimatedGif;
  12.   TempSpriteWidth: Integer;
  13.   TempSpritePosition: Integer;
  14.   TempSpriteBGRA, TempSprite: TBGRABitmap;
  15. begin
  16.   gif := TBGRAAnimatedGif.Create;
  17.   gif.LoopCount := High(Word);
  18.   TempSpriteBGRA := TBGRABitmap.Create(FSprite);
  19.   TempSpriteWidth := TempSpriteBGRA.Width div FSpriteCount;
  20.   gif.SetSize(TempSpriteWidth, TempSpriteBGRA.Height);
  21.   for i:=0 to FSpriteCount-1 do
  22.   begin
  23.     TempSpritePosition := -TempSpriteWidth * i;
  24.     TempSprite := TBGRABitmap.Create(TempSpriteWidth, TempSpriteBGRA.Height);
  25.     TempSprite.BlendImage(TempSpritePosition, 0, TempSpriteBGRA, boLinearBlend);
  26.     gif.AddFullFrame(TempSprite, FAnimSpeed);
  27.     TempSprite.Free;
  28.   end;
  29.   TempSpriteBGRA.Free;
  30.   gif.SaveToFile(Filename);
  31.   gif.Free;
  32. end;

These are on the dev branch of BGRAControls for now until a new release is done.

Maybe it's better to load individual frames instead of a sprite, then allow to save as horizontal sprite list or animated gif.

Else the user will need to make the sprite in any other software...