Analysis of drawimage usage in HTML5

Source: Internet
Author: User

In this paper, the problems encountered in the use of DrawImage in HTML5 and their solutions are analyzed. Share to everyone for your reference. The specific analysis is as follows:

Problems encountered with Image:

The

code is as follows: <! DOCTYPE html>


<html>


<head>


<meta charset= "Utf-8" >


<title></title>


<script src= "js/jquery-1.9.1.min.js" type= "Text/javascript" charset= "Utf-8" ></script>


<script type= "Text/javascript" >


$ (function () {


var jscanv = document.getElementById ("Canv");


var ocanv = Jscanv.getcontext ("2d");


var img = new Image ();


img.src = "Img.png";


ocanv.drawimage (IMG, 220, 30);


})


</script>


</head></p> <p> <body>


<canvas id= "Canv" width= "height=" >


Browser does not support


</canvas>


</body>


</html>

In fact, this type of writing is wrong, in fact, as long as a refresh picture does not show up. To ensure that the normal refresh display needs to be in the image onload time to redraw the line. Test the problems that will occur under Chrome 19.

Solution

The

code is as follows: <! DOCTYPE html>


<html>


<head>


<meta charset= "Utf-8" >


<title></title>


<script src= "js/jquery-1.9.1.min.js" type= "Text/javascript" charset= "Utf-8" ></script>


<script type= "Text/javascript" >


$ (function () {


var jscanv = document.getElementById ("Canv");


var ocanv = Jscanv.getcontext ("2d");


var img = new Image ();


img.src = "Img.png";


img.onload = function () {


ocanv.drawimage (IMG, 220, 30);


}


})


</script>


</head>


<body>


<canvas id= "Canv" width= "height=" >


Browser does not support


</canvas>


</body>


</html>

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.