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?
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With