【问题标题】:creating a gif animated file in delphi 2009?在delphi 2009 中创建一个gif 动画文件?
【发布时间】:2009-05-30 18:34:28
【问题描述】:
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');

这个只循环一次,速度不是500?

如何让它循环并设置速度?

【问题讨论】:

    标签: delphi delphi-2009


    【解决方案1】:

    编写原版TGIFImage的Anders Melander有以下answer

    您需要在 GIF 的第一帧中添加一个“Netscape Loop”扩展块。 循环块必须是您为框架定义的第一个扩展,否则它将不起作用。

    请参阅Animate demo,了解如何构建动画 GIF 的示例。

    这是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;
    

    您可以查看TGIFImage documentation here

    【讨论】:

    • 为清楚起见,您应该指定LoopExt的类型。
    【解决方案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】:

    您可以在我的主页 www.tolderlund.eu/delphi/ 上查看如何创建动画 GIF 的示例 还有用于 Delphi 5 和 Delphi 6、Delphi 7、Delphi 2005、Delphi 2006、Delphi 2007、Delphi 2009 的原始 TGIFImage。

    【讨论】:

      【解决方案4】:

      至少需要一个计时器和一些无闪烁的方法。

      参见 RXLibrary 中单元 rxAnimate.pas 中的示例 (免费提供。来源:SourceForge.net 或http://www.dummzeuch.de/delphi/english.html)。

      JVCL 也有类似组件的来源。

      【讨论】:

      • Oups .. . 对不起。我没有看到它是 TGifImage。我想创建一个 gif 动画组件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-25
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 2014-03-02
      • 2010-11-14
      • 2011-07-18
      相关资源
      最近更新 更多