[英]image width and height not showing properly in canvas using fabric js
I am using Fabricjs to upload images with the current code.我正在使用 Fabricjs 上传带有当前代码的图像。
fabric image component not rendered properly as the actual size of the image.织物图像组件未正确渲染为图像的实际大小。
here is my JS code这是我的 JS 代码
function addiMage(data) {
let myImg = './layers/' + data.name + ".png";
let left = data.bounds.left;
let top = data.bounds.top
let scaleX = data.bounds.width;
let scaleY = data.bounds.height
let blendOptions = data.blendOptions;
let index = data.index;
fabric.Image.fromURL(myImg, function (oImg) {
oImg.set({
'left': left,
'top': top,
opacity: blendOptions.opacity,
});
oImg.scaleToHeight(scaleY);
oImg.scaleToWidth(scaleX);
canvas.add(oImg);
});
}
I set the picture size like this, it can be used我是这样设置图片大小的,可以使用
fabric.Image.fromURL(myImg, (oImg) => {
oImg.scale(0.3).set({
left: setLeft(3),
top: setTop(6),
backgroundColor: "orange",
width: oImg._element.naturalWidth,
height: oImg._element.naturalHeight,
});
canvas.add(oImg);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.