Tutorial :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?


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;  


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.


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »