[英]Get height and width of Fabric.js object after modifying wrong
Here is my code. 这是我的代码。
<canvas id="c" width="240" height="300" style="border:1px solid #000000"></canvas>
<script>
var canvas = new fabric.Canvas('c');
canvas.backgroundColor = 'yellow';
canvas.renderAll();
fabric.Image.fromURL(<?php echo '"' . $url . '"'; ?>, function(myImg) {
var img1 = myImg.set({ left: 0, top: 0 ,width:150,height:150});
canvas.add(img1);
});
function objectMovedListener(ev) {
let target = ev.target;
console.log('left', target.left, 'top', target.top, 'width', target.width * target.scaleX, 'height', target.height * target.scaleY);
}
canvas.on('object:modified', objectMovedListener);
</script>
I don't understand what's going wrong. 我不明白怎么了。 object position TOP & LEFT is showing correct but height & width is shoving wrong.
对象位置TOP&LEFT显示正确,但高度和宽度推错了。
Please help me. 请帮我。
使用getScaledWidth()和getScaledHeight()分别获取对象的变换宽度和高度。
Check target.scaleX
and target.scaleY
. 检查
target.scaleX
和target.scaleY
。 If are different than 1 you need to multiply the target.width
and target.height
with scale 如果不等于1,则需要将
target.width
和target.height
乘以scale
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.