英文:
How to create a gif animation that plays only once
问题
我正在尝试生成一个只播放一次帧的动画gif。
当我将LoopCount设置为1时,它会播放两次帧。当我将LoopCount设置为0或-1时,它会无限循环。
img := image.(*image.Paletted)
outGif := &gif.GIF{}
outGif.LoopCount = 0
outGif.Image = append(outGif.Image, img)
outGif.Delay = append(outGif.Delay, 10)
f, err := os.Create("/tmp/test.gif")
if err != nil {
panic(err)
}
defer f.Close()
gif.EncodeAll(f, outGif)
如何确保它只播放一次帧?
英文:
I am trying to generate an animated gif that plays the frames only once.
When I set LoopCount to 1, it plays the frames twice. When I set LoopCount to 0 or -1, it loops infinitely.
img := image.(*image.Paletted)
outGif := &gif.GIF{}
outGif.LoopCount = 0
outGif.Image = append(outGif.Image, img)
outGif.Delay = append(outGif.Delay, 10)
f, err := os.Create("/tmp/test.gif")
if err != nil {
panic(err)
}
defer f.Close()
gif.EncodeAll(f, outGif)
How to I make sure it only plays the frames once?
答案1
得分: 0
浏览器对循环计数器的解释有所不同。对于单个循环的gif动画,Chrome循环两次,而Firefox只播放一次动画。
请参阅GifCreator - 无法创建非循环GIF图像的问题。
英文:
Browsers interpret differently the loop counter. For a single loop gif, Chrome is looping twice while Firefox is playing the animation exactly once.
See this issue of GifCreator - Unable to create non loop GIF image.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论