Home > Article > Web Front-end > How to draw pictures on js HTML5 canvas
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:
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!