html5画布线宽空间

时间:2015-01-08 13:39:25

标签: javascript html5 canvas stroke

我使用html5画布绘制像绘画我的问题,如果我用薄刷大小绘画这是很好和光滑,但如果我增加画笔大小我得到空格线。

code: http://jsfiddle.net/L2g43q1g/

细刷尺寸结果: enter image description here http://postimg.org/image/eyxenntth/

大刷子尺寸结果: enter image description here http://postimg.org/image/60agxczf9/

1 个答案:

答案 0 :(得分:2)

我认为您需要颠倒context.closePath()和context.stroke()的顺序,并添加context.lineJoin =" round"

更新了笔画功能:

function stroke(mouseX, mouseY) {
    context.beginPath();
    context.lineJoin = "round";
    context.lineWidth = 10; //1 = thin line without spaces, 10 = big line with spaces..
    context.moveTo(prevMouseX, prevMouseY);
    context.lineTo(mouseX, mouseY);
    context.closePath();
    context.stroke();


    prevMouseX = mouseX;
    prevMouseY = mouseY;
}