简体   繁体   English

FabricJS 多边形高度宽度不增加 object 大小但边界框

[英]FabricJS Polygon height width not increasing object size but bounding box

I am trying to increase size of polygon object but instead of increasing object size it is only increasing padding between object and bounding boxes.我正在尝试增加多边形 object 的大小,但不是增加 object 的大小,它只是增加 object 和边界框之间的填充。

Please see results请看结果

Here is my code:这是我的代码:

let newObject = window.saveCoordinates;

let objectWidth = fabric.util.parseUnit(params.width + 'in');
let objectHeight = fabric.util.parseUnit(params.length + 'in');

console.log(objectWidth, objectHeight)
var polygon = new fabric.Polygon(newObject, {
    left: 100,
    top: 100,
    width: objectWidth,
    height: objectHeight,
    scaleX: 1,
    scaleY: 1,
    originX: 0,
    originY: 0,
});

polygon.setCoords();
canvas.add(polygon);
canvas.renderAll();

For polygons, paths and images you want to use the scaleX and scaleY properties to set the size.对于要使用scaleXscaleY属性设置大小的多边形、路径和图像。 You can either set these values directly, or use the scaleToWidth() or scaleToHeight() methods to make the scale values calculate proportionately to fit your intended dimensions.您可以直接设置这些值,或使用scaleToWidth()scaleToHeight()方法使比例值按比例计算以适合您的预期尺寸。

If you add a working code snippet to your question I can update this answer with an example.如果您在问题中添加了一个有效的代码片段,我可以用一个例子来更新这个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM