简体   繁体   English

使用fabric js在画布中无法正确显示图像宽度和高度

[英]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.

相关问题 Fabric js - 将 Canvas 宽度和高度设置为 100% - Fabric js - Set Canvas width and height to 100% 在fabric.js 中设置画布的宽度和高度 - set width and height of canvas in fabric.js 如何在使用面料时使用CSS更改画布的高度和宽度 - How to change the height and width of canvas using css while using fabric 如何设置图像的高度和宽度,使其适合我在 fabric.js 中的 canvas 的大小? - How do I set both height and width of image so that it can fit the size of my canvas in fabric.js? 带有过滤器的背景图像未拉伸到画布的全宽 - fabric.js - Background image with filters not stretching to full width of canvas - fabric.js canvas drawimage在具有CSS高度和宽度的图像上无法正常工作 - canvas drawimage is not working properly on image with css height and width canvas object 在另一个 canvas ZA8CFDE6331BD59jsEB2AC96F8911C4B666Z 中按宽度/height 对中和缩放。 - Centering and scaling canvas object inside another canvas object by width/height in Fabric.js 在Fabric js中加载画布后如何更改其宽度 - How can we change canvas width height after it loads in Fabric js 我们如何限制Fabric.js中画布对象的最大宽度和高度 - How do we limit the maximum width and height of a canvas object in Fabric.js 使用Fabric JS在shopify中将画布导出到图像(使用toDataUrl) - Export Canvas to Image(using toDataUrl) in shopify using fabric js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM