Fabric js displaced resize rotate controls

给你一囗甜甜゛ 提交于 2019-12-08 02:34:35

问题


I have a simple fabric.canvas element which has a background and I have set its width and height equal to that of the above image. and then added the cap image. the problem is that the resize controls are displaced. I have made this clear in the image too.

This is how I am adding the canvas to the page

    $('#canvas_container').empty();
    canvas_el = document.createElement('canvas');
    canvas_el.id = "canvas";
    $('#canvas_container').append(canvas_el);
    canvas = new fabric.Canvas('canvas');

    var img = new Image();
    img.onload = function() {
      canvas.setWidth(this.width);
      canvas.setHeight(this.height);
      canvas.renderAll()
    }
    img.src =$(this).attr('picUrl');

    canvas.setBackgroundImage($(this).attr('picUrl'),function(){
      canvas.renderAll();
    });

And this is how I am adding the image

      fabric.Image.fromURL('img/hat.png', function(img) {
        oImg = img.set({ left: 50, top: 50, angle: 0 })
        canvas.add(oImg);
        canvas.renderAll();
      });

回答1:


I have got the answer on twitter.

I added a canvas.calcOffset() right after changing the width and height of the canvas and also adding the image.

It worked.




回答2:


Try with oImg.setCoords() after canvas.add(oImg);



来源:https://stackoverflow.com/questions/10926572/fabric-js-displaced-resize-rotate-controls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!