我似乎找不到一个正确的例子.我目前正在使用本网站上的方法https://developer.mozilla.org/samples/canvas-tutorial/4_5_canvas_linewidth.html
在这个例子中,应该是1px的行实际上是2px,但是更浅的颜色.这是Chrome 10和Firefox 4.
还有另一种方法来画一条线来获得我正在寻找的结果.
解决方法
However,the leftmost and all other odd-integer-width thickness lines do not appear crisp,because of the path’s positioning.
和
Obtaining crisp lines requires
understanding how paths are stroked.
In the images below,the grid
represents the canvas coordinate grid.
The squares between gridlines are
actual on-screen pixels. In the first
grid image below,a rectangle from
(2,1) to (5,5) is filled. The entire
area between them (light red) falls on
pixel boundaries,so the resulting
filled rectangle will have crisp
edges.
所以,如果你画半像素(绘制奇数像素宽度线时),那么实际的绘制边将落在绝对像素上,看起来很好.
或者您可以使用宽度为1的fillRect(x,y,width,height)
.
function draw() { var ctx = document.getElementById('canvas').getContext('2d'); for (i=0;i<10;i++){ ctx.fillRect(5 + i*14,5,1+i,140); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。