GIF animation on canvas with frame control

不想你离开。 提交于 2021-01-28 10:42:02

问题


I have some frames within gif and i want to play them on canvas with collision detection. Is there someway how to extract frames from gif with javascript?


回答1:


The short answer is that JavaScript has no simple way of controlling the current frame of an Animated GIF.

The long answer is that there are sort-of ways to do what you want with just JS, but they are very much convoluted hacks.

Example of hackish way: Create a canvas and don't add it to the DOM (so this won't be seen by anyone). In a fast loop (setTimeout), draw to this canvas constantly and collect snapshots. Compare the canvas ImageData to see if the frames have changed or not.



来源:https://stackoverflow.com/questions/12143157/gif-animation-on-canvas-with-frame-control

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