【发布时间】:2010-12-16 07:48:06
【问题描述】:
我正在尝试使用 Canvas,将不同颜色的标记放在网格上,并尝试将它们移除。
我目前正在尝试通过在令牌上绘制一个尺寸完全相同的白色圆圈来移除令牌。这会在原始圆圈所在的位置留下一个“鬼环”(单像素轮廓),随着白色圆圈的连续应用而消失。
2,-1 中的圆圈是最初绘制的,并没有被重绘。 3, -1 中的圆圈被重绘了一次,4, -1 中的圆圈被重绘了两次,以此类推到 7, -1。
Chrome 和 Firefox 3.6 都会出现这种行为
我的代码如下。
function placeToken(e) {
var click = getClick(e);
var gridCord = getGridCord(click);
var canvas = e.currentTarget;
var ctx = canvas.getContext(CONTEXT_NAME);
ctx.fillStyle = color;
ctx.strokeStyle = color; //tried with and without this line, no effect
x = (gridCord.x * spacing) + (spacing / 2);
y = (gridCord.y * spacing) + (spacing / 2);
ctx.beginPath();
ctx.arc(x, y, (spacing - tokenEdge) / 2, 0, Math.PI * 2, true);
ctx.closePath();
ctx.fill();
ctx.stroke(); //tried with and without this line. Same result
};
为什么canvas会留下这个Ghostly ring,我该如何摆脱它?
【问题讨论】:
-
flash 开发人员都知道画布出没了
-
简而言之,抗锯齿。该圆圈边缘上的像素正在以低于 100% 的不透明度进行绘制。这不是画布独有的。你只需要在上面画画。
标签: javascript html canvas