【发布时间】:2014-07-10 18:27:27
【问题描述】:
出于好奇,我想尝试设置lineWidth < 1,因为即使我的分辨率设置正确,1px 的线条看起来也很胖。不出所料,它不起作用,但在 Chrome 和 Firefox 上存在这种奇怪的行为(未在其他地方测试过):
左边是lineWidth = 1,中间是lineWidth = 0.5,右边是lineWidth = 0.1
它们是使用以下代码生成的:
ctx.lineWidth = 0.1;
lis.each(function(i) {
sx = $(this).offset().left;
sy = $(this).offset().top;
ex = sx - (20 * (6-i));
ey = wh - 80 - (20 * (i + 1));
eey = ey - (20 * i);
// Horizontal
ctx.moveTo(sx,sy+7);
ctx.lineTo(ex, sy+7);
ctx.stroke();
// Vertical
ctx.moveTo(ex,sy+7);
ctx.lineTo(ex, ey);
ctx.stroke();
// Horizontal
ctx.moveTo(ex,ey);
ctx.lineTo(ww - bg_img_width + 100, eey);
ctx.stroke();
});
它们按照子代的出现顺序打印,因此每次都以 Alpha 开头,以 Epsilon 结尾。
谁能解释为什么当0 < lineWidth < 1 时,随着循环的进行,线条会变细?这是故意的吗?可以用来做很酷的东西吗?
【问题讨论】:
-
我猜这是因为抗锯齿和亚像素抗锯齿。它可能不依赖于使用的图形驱动程序/操作系统,因为我很确定画布线操作会加速。