Sunday, July 17, 2022

[FIXED] How to get frame delay from animated gif?

Issue

I try resize animated gif. I resize each frame as bitmap and then make new animated gif but I don't know how to get frame delay for same speed animation as in original gif.

uses Gifimg;

procedure TForm1.FormCreate(Sender: TObject);
var
  gif: TGIFImage;
  bmp,bmp2: TBitmap;
  i:integer;
  gifren: TGIFRenderer;
  gif2:TGifImage;
begin
  gif:=TGIFImage.Create;
  gif2:=tgifimage.Create;
  bmp:=TBitmap.Create;
  bmp2:=TBitmap.Create;
    gif.LoadFromFile('d:\z.gif');
    gifren:=TGIFRenderer.Create(gif);
      for i:=0 to gif.Images.Count-1 do begin
      bmp.SetSize(gif.Width, gif.Height);
      gifren.Draw(bmp.Canvas, bmp.Canvas.ClipRect);
       bmp2.SetSize(1111,1111);
        bmp2.Canvas.StretchDraw(Rect(0, 0, 1111, 1111), bmp);

        TGIFGraphicControlExtension.Create(gif2.add(bmp2)).Delay:=10;
        gifren.NextFrame;
      end;
   TGIFAppExtNSLoop.Create(Gif2.Images.Frames[0]).Loops:=0;
   Gif2.SaveToFile('d:\gif.gif');
 end;

Solution

Refer to help Vcl.Imaging.GIFImg.TGIFRenderer.FrameDelay

Specifies the delay time before moving to the next frame in an animated GIF.

But do consider that the resized image may require more time to render, and it may not be possible to keep up the pace.



Answered By - Tom Brunberg
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.