HTML5之Canvas绘图——图像切割函数clip

<!DOCTYPE html>
<html>
 <head>
    <meta charset="utf-8">
    <title>Canvas</title>
 </head>
 <style type="text/css">
    body{margin:20px auto; padding:0; width:800px; }
    canvas{border:dashed 2px #CCC}
 </style>
 <script type="text/javascript">
    function $$(id){
        return document.getElementById(id);
    }
    function pageLoad(){
        var can = $$('can');
        var cans = can.getContext('2d');
        var objImg = new Image();
        objImg.src = 'lin.jpg';
        objImg.onload = function (){
            cans.drawImage(objImg,0,0,800,600);
        }
        cans.beginPath();
        cans.arc(400,300,200,0,Math.PI*2,1);
        cans.closePath();
        cans.clip();
    }
    function img_click(){
        var can = $$('can');
        var cans = can.getContext('2d');
        cans.clearRect(0,0,800,600);
    }
 </script>
<body onload="pageLoad();">
    <canvas id="can" width="800px" height="600px" onclick="img_click(this);"></canvas>
</body>
</html>

我猜你肯定想要原图片素材了,嘻嘻,以前的文章里有~~

posted @ 2012-11-27 15:52  小 伍  阅读(1674)  评论(0编辑  收藏  举报