如何更改Fabric.Path对象的宽度\高度?参数宽度\构造函数的高度不工作

发布于 2025-01-28 10:33:25 字数 463 浏览 1 评论 0原文

我使用织物JS并尝试传递织物的宽度和高度。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',      
});

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

我在哪里错了,如何设置织物的大小。

I use fabric-js and try to pass width and height of fabric.Path via params in constructor like so:

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',      
});

It works fine, but I can't affect to "image size". I pass different values but nothing changes.

Where am I wrong and how can I set size of fabric.Path object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑看君怀她人 2025-02-04 10:33:25

可以通过更改scalexscaley值来调整路径对象。

为了获得特定的宽度或高度,您还可以使用scaletowidth()scaleteheight()方法。

http://fabricjs.coms.coms.com/docs/docs/docs/fabric.path.html#scaletoheight
http://fabricjs.coms.coms.com/docs/docs/docs/fabric.path.html#scaletowidth

Path objects can be resized by changing the scaleX and scaleY values.

To achieve a specific width or height, you can also use the scaleToWidth() and scaleToHeight() methods.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文