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>