creating a gif animated file in delphi 2009?

◇◆丶佛笑我妖孽 提交于 2019-12-06 02:09:13

问题


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?


回答1:


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.




回答2:


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;



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/930300/creating-a-gif-animated-file-in-delphi-2009

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!