zoukankan      html  css  js  c++  java
  • html5 canvas裁剪区域

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>canvas裁剪区域</title>
    <script src="js/modernizr.js"></script>
    </head>
    
    <body>
    <script type="text/javascript">
    window.addEventListener('load',eventWindowLoaded,false);
    function eventWindowLoaded(){
    	canvasApp();
    }
    function canvasSupport(){
    	return Modernizr.canvas;
    }
    function canvasApp(){
    	if(!canvasSupport()){
    		return;
    	}else{
    		var theCanvas = document.getElementById('canvas')
    		var context = theCanvas.getContext("2d")
    
    	}
    	drawScreen();
    	function drawScreen(){
    		context.fillStyle = "green";
    		context.fillRect(10,10,200,200);
    		context.save();
    		context.beginPath();
    		
    		context.rect(0,0,50,50);
    		context.clip();
    		//红色圆
    		context.beginPath();
    		context.strokeStyle="red";
    		context.lineWidth=5;
    		context.arc(100,100,100,(Math.PI/180)*0,(Math.PI/180)*360,false);
    		//整理
    		context.stroke();
    		context.closePath();
    		context.restore();
    		//再次裁剪整个画布
    		context.beginPath();
    		context.rect(0,0,200,200);
    		context.clip();
    		//绘制一个没有裁剪的蓝线
    		context.beginPath();
    		context.strokeStyle="blue";
    		context.lineWidth=5;
    		context.arc(100,100,50,(Math.PI/180)*0,(Math.PI/180)*360,false);
    		//整圆
    		context.stroke();
    		context.closePath();
    		
    		
    		
    	}
    		
    }
    
    
    </script>
    <canvas id="canvas" width="500" height="500">
    你的浏览器无法使用canvas
    如有问题,请在下方发送你问题,我看到会解答!!
    </canvas>
    </body>
    </html>
    

    首先有个200*200的矩形是绿色的

    然后裁剪50*50.。下面那个圆弧只有50*50的区域内了

    然后再切换回200*200

    然后那个蓝色的圆又看到了

    大概的意思就是这样

    最近忙着面试啥的搞得没时间把我的canvas整理一下!

    现在开始继续整理!!!

  • 相关阅读:
    Codeforces Round #325 (Div. 2) F:(meet in the middle)
    Educational Codeforces Round 3:E (MST+树链剖分+RMQ)
    Educational Codeforces Round 3:D. Gadgets for dollars and pounds(二分答案+贪心)
    CodeForce 484B:(最大余数)
    CodeForce 540C:(DFS)
    HDU 1010:(DFS)
    Poj1741-Tree(树分治)
    uva10245-The Closest Pair Problem(平面上的点分治)
    hdu1561-The more, The Better(树形dp)
    hdu2196-Computer(树形dp)
  • 原文地址:https://www.cnblogs.com/LoveOrHate/p/4414965.html
Copyright © 2011-2022 走看看