【发布时间】:2014-08-26 19:42:19
【问题描述】:
我正在使用画布。我已经绘制了一个像截图中一样的形状,但是如果我尝试填充它,它会错误地填充,如截图所示。
这是我的代码
<canvas id="myCanvas" width="800" height="650" style="border:1px solid #d3d3d3;">
<script>
var c=document.getElementById('myCanvas');
var ctx=c.getContext('2d');
ctx.save();
ctx.beginPath();
ctx.moveTo(81.75, 319.5);
ctx.arc(198, 319.5, 116.25, -3.140796326794897, 0.0007963267948964958, false);
ctx.lineTo(210.91666666666666,319.5);
ctx.moveTo(81.75, 319.5);
ctx.arc(198, 319.5, 12.916666666666668, -3.140796326794897, 0.0007963267948964958, false);
ctx.strokeStyle = "#00ff00";
ctx.fillStyle = "#00ff00";
//ctx.fill(); - Here the problem is
ctx.stroke();
ctx.restore();
</script>
请提供解决方案来克服这个问题。 谢谢。
【问题讨论】:
-
w3schools.com/tags/canvas_clip.asp 说:“注意:如果路径没有关闭,fill()方法会在路径的最后一点到起点添加一条线来关闭路径(如closePath( )),然后填充路径。”另外,看看这个教程:html5canvastutorials.com/tutorials/html5-canvas-shape-fill
标签: jquery html canvas html5-canvas