HTML5画笔笔尖

时间:2012-02-27 09:49:21

标签: html5 brush

我正在尝试获得圆形笔尖,但下面的代码会创建一个带有线条形状的笔尖。

context.lineWidth = 1;
context.lineCap = "round";

如何获得圆形笔尖?

1 个答案:

答案 0 :(得分:2)

您只需绘制画布的路径并将lineCap设置为round

var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");

context.beginPath();
context.moveTo(10, 10);
context.lineTo(canvas.width/2, canvas.height / 2);
context.lineWidth = 10;
context.strokeStyle = "red";
context.lineCap = "round";
context.stroke();

另见example in the Mozilla Developer Network