码迷,mamicode.com
首页 > Web开发 > 详细

HTML5之canvas 9绘制图片

时间:2016-09-06 14:01:47      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:

绘制图片

Var image=new Image();

image.src=” http://img4.duitang.com/uploads/item/201406/25/20140625182321_4MTau.thumb.700_0.jpeg”;

image.onload=function(){}

Context.drawImage(image,x,y);

Context.drawImage(image,x,y,w,h);

Context.drawIamge(image,sx,sy,sw,sh,dx,dy,dw,dh);

图片平铺

技术分享

Var pat= context.createPattern(image,”repeat”);

Context.fillStyle=pat;

Context.fillRect(0,0,400,300);

图片裁剪

技术分享

 

绘制好路径

 

Context.clip();

<html>

	<head>
		<meta charset="UTF-8">
		<title>绘制图片</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

	</head>

	<body>
		<canvas id="canvas" width="500" height="500"></canvas>
		
		<script type="text/javascript">
			var oCanvas = document.getElementById("canvas");
			var context = oCanvas.getContext("2d");
			context.fillStyle = "#ededed";
			context.fillRect(0, 0, 500, 500);

			//绘制图片
			var img = new Image(); //创建
			img.src = "img/01.jpg"; //图片地址
			img.onload = function() { //检测所有图像信息载入页面里
				context.drawImage(img, 0, 0); // img对象;0,0:img坐标起点
			};
		</script>
	</body>

</html>

  

 

HTML5之canvas 9绘制图片

标签:

原文地址:http://www.cnblogs.com/Abner5/p/5845386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!