How to draw a GIF animated picture in a canvas canvas in HTML5

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.