怎么让图片绘制出来是圆形的
来源:6-6 编程练习
qq_上帝之手_3
2017-12-31 02:25:41
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext('2d');
ctx.save();
ctx.fillRect(0,0,canvas.width,canvas.height);
var img=new Image();
img.src="http://climg.mukewang.com/59a7df40000165fa06000600.jpg";
//一定要在图像加载完成后的回调中绘制图像
img.onload=function(){//只有在onload函数中图像才能绘制出来
ctx.drawImage(img, 0, 0, 500, 300,100,100,100,100);//第四个第五个参数是宽高
}
ctx.restore();
ctx.beginPath();
ctx.translate(100,100);
ctx.arc(150,150,80,0,Math.PI*2,true);
ctx.fillStyle="rgb(120,109,97)";
ctx.fill();
1回答
小丸子爱吃菜
2017-12-31
图片无法去绘制成圆形的,只能尽量的使背景颜色贴近于图片的背景颜色。
祝学习愉快!
相似问题