如何更改 fabric.Path 对象的 width\height?构造函数中的参数 width\height 不起作用

How to change width\height of fabric.Path object? Params width\height in constructor don't work

我使用 fabric-js 并尝试通过构造函数中的参数传递 fabric.Path 的宽度和高度,如下所示:

const path = 'M16.2777 24.96C15.4876 26.3467 13.5124 26.3467 12.7223 24.96L0.27808 3.12C-0.512027 1.73333 0.475607 0 2.05582 0H26.9442C28.5244 0 29.512 1.73333 28.7219 3.12L16.2777 24.96Z';

const mapObject = new fabric.Path(path , {
  width: 30, //
  height: 30, //
  left: 100,
  top: 100,
  fill: '#c9c9c9',      
});

它工作正常,但我无法影响“图像大小”。我传递了不同的值,但没有任何变化。

我哪里错了,如何设置 fabric.Path 对象的大小?

可以通过更改 scaleXscaleY 值来调整路径对象的大小。

要达到特定的宽度或高度,您还可以使用scaleToWidth()scaleToHeight()方法。

http://fabricjs.com/docs/fabric.Path.html#scaleToHeight http://fabricjs.com/docs/fabric.Path.html#scaleToWidth