如何更改Fabric.Path对象的宽度\高度?参数宽度\构造函数的高度不工作
我使用织物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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以通过更改
scalex
和scaley
值来调整路径对象。为了获得特定的宽度或高度,您还可以使用
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
andscaleY
values.To achieve a specific width or height, you can also use the
scaleToWidth()
andscaleToHeight()
methods.http://fabricjs.com/docs/fabric.Path.html#scaleToHeight
http://fabricjs.com/docs/fabric.Path.html#scaleToWidth