HTML5 canvas绘制图片

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>

 

  图片:

效果:

 

 

 2017-09-08  08:09:02

posted @ 2017-09-08 08:10  1点  阅读(323)  评论(0编辑  收藏  举报