views:

1119

answers:

4
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?

A: 

Need at least a timer and some flicker free methods.

See example in unit rxAnimate.pas from the RXLibrary (available free. Sources at SourceForge.net or http://www.dummzeuch.de/delphi/english.html).

There is also sources for a similar component at JVCL.

volvox
Oups .. .sorry. I did not see it was a TGifImage. I though of creating a gif animated component.
volvox
+3  A: 

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.

stukelly
A: 
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;
isa
A: 

You can se an example of how to create an animated GIF, on my homepage www.tolderlund.eu/delphi/ There is also the original TGIFImage for Delphi 5 and for Delphi 6, Delphi 7, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009.