How to play gif inside canvas in HTML5

前端 未结 3 456
醉梦人生
醉梦人生 2020-12-18 08:18

I want to play gif inside a canvas. i hav used the following code. bt it is not working. plz tel me wat is wrong in my code or any other way of doing it.

var         


        
相关标签:
3条回答
  • 2020-12-18 08:30

    You cannot as canvas doesn't provide any methods to deal with animated gifs. You should split gif into single frames then create a spritesheet and animate it copying current frame.

    0 讨论(0)
  • 2020-12-18 08:37

    I found an article that answers your question. Basically, when you add an animated gif to a canvas element it displays the exact state the image is at when it's included. So, as rezoner says, you need to create a spritesheet and animate it using javascript.

    0 讨论(0)
  • 2020-12-18 08:56

    You can actually decode the GIF with JavaScript and write the frames to canvas. Check http://slbkbs.org/jsgif/

    0 讨论(0)
提交回复
热议问题