We all know how to draw a static picture (JPEG, PNG, etc.) on a canvas canvas of HTML5, and just use the DrawImage method in canvas, so how do I draw a motion picture (GIF)?
I believe we all know that the dynamic picture is dynamic, because it is a lot of pictures in a certain number of frames in order to play, so we can also simulate such a number of frames, every time to re-
Draw a picture, you can draw a dynamic picture? The answer, of course, is yes. Here is an example of my own test, the code is as follows:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8" />5 <title>Canvas to draw a dynamic map, video can also be drawn</title>6 7 <Scripttype= "Text/javascript">8 window.onload= function() {9 varimg=document.getElementById ('IMG1');Ten varcan=document.getElementById ('can'); One varCXT=Can.getcontext ('2d'); A - - SetInterval (function() {Cxt.drawimage (IMG,0, 0);}, -); the } - </Script> - </Head> - + <Body> - <P>Ready to draw the animated picture:</P> + <imgID= "IMG1"src= "Ex.gif"alt= "Your browser does not support IMG tags"></img> A <P>Animated pictures drawn on canvas:</P> at <CanvasID= "Can"width= "800px"Height= "600px"style= "Background-color: #CCCCCC">Your browser does not support canvas labels</Canvas> - </Body> - </HTML>
This is an example of the dynamic picture resource ex.gif used in this article: