具有帧控制的画布上的GIF动画

具有帧控制的画布上的GIF动画

本文介绍了具有帧控制的画布上的GIF动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gif内有一些帧,我想通过碰撞检测在画布上播放它们.有什么方法可以使用javascript从gif提取帧吗?

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?

推荐答案

简短的答案是JavaScript没有简单的方法来控制动画GIF的当前帧.

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

很长的答案是,只有JS可以使用多种方法来完成您想做的事情,但是它们是非常复杂的黑客.

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.

骇客方式的示例:创建一个画布,并且不要将其添加到DOM中(这样任何人都不会看到它).在快速循环(setTimeout)中,不断绘制此画布并收集快照.比较画布ImageData以查看框架是否已更改.

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.

这篇关于具有帧控制的画布上的GIF动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:15