javascript - Fabric.js canvas toDataUrl - Stack Overflow

I have a problem with export fabric's canvas to url. How can I export all content with imes from c

I have a problem with export fabric's canvas to url.

How can I export all content with imes from canvas to url? Because for now, I can see that only red background has been exported.

Here's my fiddle : /

<div id="custom-label" style="position: absolute; right: 0px; top: 50px; z-index:10; width: 512px; height: 256px; border: 1px solid #7d8d20">
  <canvas id="draw-area" width="512" height="256" style=""></canvas>
</div>

I have a problem with export fabric's canvas to url.

How can I export all content with imes from canvas to url? Because for now, I can see that only red background has been exported.

Here's my fiddle : https://jsfiddle/y7pu4wn3/13/

<div id="custom-label" style="position: absolute; right: 0px; top: 50px; z-index:10; width: 512px; height: 256px; border: 1px solid #7d8d20">
  <canvas id="draw-area" width="512" height="256" style=""></canvas>
</div>

Share Improve this question edited Aug 8, 2018 at 8:35 Vadim Kotov 8,2848 gold badges50 silver badges63 bronze badges asked Oct 4, 2017 at 13:54 Logan 03Logan 03 451 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Your result is correct. You are getting canvas data before image is loaded. Loading images are async. If you will do like this (using your fiddle):

fabric.Image.fromURL(imageObj.src, function(myImg) {
                canvas.add(myImg); 

                var pngURL = canvas.toDataURL();
                console.log(pngURL);

                $('#placeHolder').html('<img src="'+pngURL+'"/>');

              });

It will not work because, image is from different domain. If your actual project has images on the same domain you can try code above. If it is from different domain, so it will be more plicated to do then your logic

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744714755a4589551.html

相关推荐

  • javascript - Fabric.js canvas toDataUrl - Stack Overflow

    I have a problem with export fabric's canvas to url. How can I export all content with imes from c

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信