2009-05-30 86 views
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'); 

這隻循環一次,速度不是500?在delphi 2009中創建一個gif動畫文件?

如何讓它循環和設置速度?

回答

-1

至少需要一個計時器和一些無閃爍的方法。

查看來自RXLibrary (可在SourceForge.net上獲得的免費來源或http://www.dummzeuch.de/delphi/english.html)的單元rxAnimate.pas中的示例。

JVCL還有類似組件的來源。

+0

Oups .. .sorry。我沒有看到它是一個TGifImage。我雖然創建一個GIF動畫組件。 – volvox 2009-05-30 19:55:45

6

安德斯梅蘭德,誰寫了原始TGIFImage,有以下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

+0

爲了清楚起見,您應該指定'LoopExt'的類型。 – 2014-08-24 19:41:30

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; 
+0

+1。我非常喜歡這種風格。 – 2014-08-24 19:57:49

+1

...直到我意識到它被打破。顯然,NS循環必須在第一個GCE之前插入。請參閱http://stackoverflow.com/a/25480538/282848 – 2014-08-25 18:48:55

1

您可以硒如何創建一個GIF動畫,在我的主頁爲例www.tolderlund.eu/delphi/ 還有原TGIFImage德爾福5和6德爾福,德爾福7,德爾福2005,Delphi 2006,Delphi 2007,Delphi 2009.