Home >Web Front-end >JS Tutorial >Detailed explanation of how to draw pictures using canvas in js+HTML5

Detailed explanation of how to draw pictures using canvas in js+HTML5

巴扎黑
巴扎黑Original
2017-09-09 10:12:341736browse

This article mainly introduces the method of drawing pictures with js HTML5 canvas in detail. It has certain reference value. Interested friends can refer to it.

The example in this article shares with you the HTML5 canvas drawing. The specific code of the picture is for your reference. The specific content is as follows

demo.js


window.onload=function() {
  createcanvas();
 
  drawImage();
}
 function createcanvas() {
   var CANVAS=document.getElementById('mycanvas');
   context=CANVAS.getContext('2d');
 }
 
function drawImage() {
  var img=new Image();
  img.onload=function() {
    context.drawImage(img,0,0,200,200 );
  }
  img.src="img5.jpg";
}

demo.html


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>canvas</title>
 
  <script type="text/javascript" src="demo.js"></script>
</head>
<body>
  <canvas id="mycanvas"  width="400" hight="400" >
<span>你的浏览器不支持canvas</span>
</canvas>
 
</body>
</html>

Picture:

Effect:

The above is the detailed content of Detailed explanation of how to draw pictures using canvas in js+HTML5. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn