Home > Web Front-end > HTML Tutorial > How to draw pictures on js HTML5 canvas

How to draw pictures on js HTML5 canvas

不言
Release: 2018-06-05 15:20:35
Original
2127 people have browsed it

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";
}
Copy after login

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>
Copy after login

Picture:

Effect:

Related recommendations:

HTML5 canvas basic drawing drawing lines

js method to get the value of the span tag of html (super simple)

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template