javascript - 如何在 html5 Canvas 中绘制 Fabric js strokeRect?

标签 javascript html canvas html5-canvas fabricjs

我正在使用 html5 Canvas 库 Fabric js 绘制形状:

代码: canvas.add(new fabric.Rect({top: 100, 左:100, 宽度:50, 高度:50, 填充:'空', 中风:'白色', 笔划宽度:1}));

但是它在我不想要的中间区域填充黑色。 我想要 html5 canvas 中的 strokeRect 之类的功能。 有什么建议吗?

最佳答案

使用transparent而不是empty填充矩形。

示例:

canvas.add(new fabric.Rect({top: 100,
    left: 100,
    width: 50,
    height: 50,
    fill: 'transparent',
    stroke: 'white',
    strokeWidth: 1
}));

关于javascript - 如何在 html5 Canvas 中绘制 Fabric js strokeRect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33062976/

相关文章:

javascript - Django-Chartit 'source' 必须是查询集、模型或管理器

html - Bootstrap 带插入符号的导航元素

javascript - 单击内部复选框时使用 jQuery 添加类以包含 li

javascript - JS/HTML5 - 使用数组中的图像数据重绘 Canvas

javascript - 原型(prototype)和关闭

javascript - 如何仅在第一次点击时通过 react-query 获取数据,然后在后续点击时禁用重新获取

javascript - Python 创建的简单 HTML/Javascript 页面显示为空白

Angularjs 指令 Canvas 模糊

html - 如何使用 CSS 显示 :grid, 来定义内容大小而不是容纳它

javascript - 如何在 React 中根据宽度动态设置图像高度?