Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a gif animated file in delphi 2009?

gif := TgifImage.Create;
gif.Width := 100;
gif.Height := 100;
gif.AnimationSpeed := 500;
gif.Animate := true;
gif.add(image1.Picture.Bitmap);
gif.add(image2.Picture.Bitmap);
gif.add(image3.Picture.Bitmap);
gif.SaveToFile('gif.gif');

This loops just once and the speed is not 500?

How to make it loop and set the speed?

like image 337
isa Avatar asked May 30 '09 18:05

isa


2 Answers

Anders Melander, who wrote the original TGIFImage, has the following answer.

You need to add a “Netscape Loop” extension block to the first frame of your GIF. The loop block must be the first extension you define for the frame or else it will not work.

See the Animate demo for an example of how to build an animated GIF.

Here is a code excerpt from the Animate demo:

// Add the source image to the animation
Result := GIF.Add(Source);

// Netscape Loop extension must be the first extension in the first frame!
if (GIF.Images.Count = 1) then
begin
  LoopExt := TGIFAppExtNSLoop.Create(Result);
  LoopExt.Loops := 0; // Number of loops (0 = forever)
end;

You can view the TGIFImage documentation here.

like image 75
stukelly Avatar answered Sep 28 '22 20:09

stukelly


var Gif:TGifImage;
begin
    //Setting the delay for each frame
    TGIFGraphicControlExtension.Create(Gif.Add(image1.Picture.Bitmap)).Delay := 300;
    TGIFGraphicControlExtension.Create(Gif.Add(image2.Picture.Bitmap)).Delay := 300;
    TGIFGraphicControlExtension.Create(Gif.Add(image3.Picture.Bitmap)).Delay := 300;
    //Adding loop extension in the first frame (0 = forever)
    TGIFAppExtNSLoop.Create(Gif.Images.Frames[0]).Loops := 0;

    Gif.SaveToFile('gif.gif');
end;
like image 30
isa Avatar answered Sep 28 '22 20:09

isa