Home >Web Front-end >JS Tutorial >Detailed explanation of how to draw pictures using canvas in js+HTML5
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!