相关疑难解决方法(0)

Fabric.js:如何填充徒手路径来绘制形状?

在fabric.js中,我们可以徒手绘制路径(例如http://fabricjs.com/freedrawing)。

但是,在 HTML canvas 2d-context ctx 中,我也可以绘制一条路径,然后调用

ctx.fill()

填充路径并从路径中制作填充形状。

示例代码:每当鼠标抬起时,路径就会被填充。

function draw() {

ctx.lineCap = "round";
ctx.globalAlpha = 1;

var x = null;
var y = null;

canvas.onmousedown = function (e) {

    // begin a new path
    ctx.beginPath();

    // move to mouse cursor coordinates
    var rect = canvas.getBoundingClientRect();
    x = e.clientX - rect.left;
    y = e.clientY - rect.top;
    ctx.moveTo(x, y);

    // draw a dot
    ctx.lineTo(x+0.4, y+0.4);
    ctx.stroke();
};

canvas.onmouseup = function (e) {
    x = null;
    y = …
Run Code Online (Sandbox Code Playgroud)

javascript path shapes fill fabricjs

3
推荐指数
1
解决办法
3704
查看次数

标签 统计

fabricjs ×1

fill ×1

javascript ×1

path ×1

shapes ×1