- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 HTML Canvas,如果你画一条虚线是这样的:
ctx.lineWidth = 40;
ctx.lineCap = 'round';
ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.moveTo(100,100);
ctx.lineTo(150,200);
ctx.moveTo(200,300);
ctx.lineTo(250,400);
ctx.moveTo(300,500);
ctx.lineTo(350,600);
ctx.closePath();
ctx.stroke();
那么结果是这样的:
(来源:phrogz.net)
正如您在 this test page 上看到的那样, 在最后一个 lineTo
修复最后一个线段以使用圆角大写字母后添加一个“多余的” moveTo
调用。
我准备将此作为错误记录,但后来我发现该行为在 Safari v5、Chrome v8 以及 FireFox v3.6 和 v4.0b 上是相同的。这让我相信这是故意的。
此行为在标准中的何处指定,以及(如果您能辨别)为什么这样指定?
最佳答案
这里是来自 canvas spec (section 9, paths) 的相关定义:
The
moveTo(x, y)
method must create a new subpath with the specified point as its first (and only) point.The
lineTo(x, y)
method ... must connect the last point in the subpath to the given point (x, y) using a straight line, and must then add the given point (x, y) to the subpath.The
closePath()
method ... must mark the last subpath as closed ... this is equivalent to adding a straight line connecting the last point back to the first point, thus "closing" the shape ...
每个 moveTo
调用都会创建一个新的子路径,从而结束前一个子路径。在您的情况下,前两个部分以这种方式结束。对于最后一段,调用 closePath
通过在相反方向绘制另一段来“关闭”该段,因此您看到的结果是——没有一个段,而是两个重叠的段。添加另一个 moveTo
会像其他部分一样结束此段,因此您会看到预期的圆角线帽。
关于html - 为什么 HTML Canvas rounded lineCap 对于最后一段失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4577430/
我想为 CAShapeLayer 的 lineCap 属性设置动画。这是我的代码: func animate() { let animation = CABasicAnimation(ke
我有这个代码: context.lineWidth = 10; context.lineCap = "square"; context.lineJoin = "square"; context.str
我已经为进度条实现了一个基本的线条绘制动画。这条线有一个圆帽边。当我为线条绘制动画时,线条的开头有一个圆帽,但最后是一个正方形。下面是我正在使用的代码,我遗漏了什么吗?? CAShape层代码: C
这是我的代码: canvas.lineCap = "round"; canvas.lineWidth = 15; canvas.beginPath(); canvas.moveTo(100, 100)
使用 HTML Canvas,如果你画一条虚线是这样的: ctx.lineWidth = 40; ctx.lineCap = 'round'; ctx.strokeStyle = 'red
我有一个圆弧,我画了如下: func drawBackgroundMask(context: CGContextRef, center: CGP
从列表中选择选项时如何更新 lineJoin 和 lineCap? https://jsfiddle.net/7cao1r1b/ round miter 在js中: function ha
当我意识到它可能是 Firefox 中的一个错误时,我正在回答 Stack Overflow 上的一个问题,同时使用 stroke-linecap="round" 和 vector-effect= “
谁能给我一个这些属性的例子:stroke-dasharray、stroke-linecap、stroke-linejoin 我试过使用它们,但我不太理解它们值的 sentext 结构。 最佳答案 Ph
我是一名优秀的程序员,十分优秀!