繁体   English   中英

增加画布中形状的边框宽度

[英]Increase the width of a border for a shape in canvas

我创建了画布,并使用Javascript在画布中创建了一个圆圈。 我使用stroke()给圆加了边框,但是我不确定如何增加边框的宽度。 我以为可以使用strokeWidth() ,但是不确定。

 var c=document.getElementById('canvas'); var ctx=c.getContext('2d'); ctx.beginPath(); ctx.fillStyle="blue"; ctx.arc(150,73,70,0,2*Math.PI); ctx.fill(); ctx.strokeStyle="yellow"; ctx.stroke(); ctx.closePath(); 
 #canvas{ height: 250px; width: 500px; background-color: orange; border: 1px solid black; margin-left: auto; margin-right: auto; left: 0; right: 0; display:block; } 
 <canvas id="canvas" width=500 height=250></canvas> 

您可以使用.lineWidth属性来增加边框的粗细,如下所示:


 var c = document.getElementById('canvas'); var ctx = c.getContext('2d'); ctx.beginPath(); ctx.fillStyle = "blue"; ctx.arc(150, 73, 70, 0, 2 * Math.PI); ctx.fill(); ctx.lineWidth = 10; ctx.strokeStyle = "yellow"; ctx.stroke(); ctx.closePath(); 
 #canvas { height: 250px; width: 500px; background-color: orange; border: 1px solid black; margin-left: auto; margin-right: auto; left: 0; right: 0; display: block; } 
 <canvas id="canvas" width=500 height=250></canvas> 

尝试使用ctx.lineWidth=10; 更多信息可以在这里找到。

您可以使用.lineWidth属性来增加边框的粗细,例如:

ctx.lineWidth = 10;

注意:必须在调用stroke()之前设置lineWidth属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM