Add image from user computer to canvas

前端 未结 2 1009
独厮守ぢ
独厮守ぢ 2020-12-06 12:06

i\'m working on a web app that allow users to create dynamic slideshow. Currently i\'ve got an issue regardless how to add image from the computer\'s user to the canvas. I\'

2条回答
  •  时光说笑
    2020-12-06 12:43

    There is one basic mistake in your code, you are trying to add the image data to the src attribute of the fabric.Image object.

    What you need to do, is to create an Image object with your result, and pass it to the fabric.Image object, like this:

    var imgObj = new Image();
    imgObj.src = event.target.result;
    imgObj.onload = function () {
      var image = new fabric.Image(imgObj);
    }
    

    I made a working example here: http://jsfiddle.net/jaibuu/Vp6wa/

提交回复
热议问题