canvas学习之基础

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
	body{margin: 0;padding: 0;}
	body,html{width: 500px;height: 500px;}
	#scream{display: none;}
	/*body,html{width: 100%;height: 100%;}*/
</style>
</head>
<body>
	<img id="scream" src="../../小效果/cookie:封装留言板和照片墙/img/2.jpg"/>
	<canvas id="can" width= "800" height="400" >你得浏览器版本低了</canvas>
	<script>
//		can.style.cssText = "display:block; ";//width: 800px;height: 400px;
		//对象是内建的 HTML5 对象,拥有多种绘制路径、矩形、圆形、字符以及添加图像的方法。
		var ctx = can.getContext("2d");
/*		//绘制矩形
		ctx.fillStyle="#000000";
		ctx.fillRect(10,10,50,50);//fillRect(x,y,width,height) x,y 坐标 
*//*	//绘制线条
  		//从坐标 (0,0)开始到 (200,100)结束 stroke绘制线条
		ctx.moveTo(0,0);
		ctx.lineTo(200,100);
		ctx.stroke();
*//*	//绘制圆
		ctx.beginPath();
		ctx.arc(95,50,40,0,2*Math.PI);//arc(x,y,r,start,stop)
		ctx.stroke();
*//*		//绘制文字
		ctx.font="30px Arial";//font - 定义字体
		//fillText(text,x,y) - 在 canvas 上绘制实心的文本
		//strokeText(text,x,y) - 在 canvas 上绘制空心的文本
		ctx.fillText("Hello World",10,50);
		ctx.strokeText("Hello World",10,100);
*//*	//绘制渐变	
		// 创建渐变
		var grd=ctx.createLinearGradient(0,0,200,0);
		grd.addColorStop(0,"red");
		grd.addColorStop(1,"white");
		// 填充渐变
		ctx.fillStyle=grd;
		ctx.fillRect(10,10,150,80);
*/		
		var img=document.getElementById("scream");
		img.onload = function (){
			ctx.drawImage(img,10,10);
		}
		
		
	</script>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值