When the canvas has a background image, canvas.toDataURL ('png') stops working

I set the canvas background image using:

canvas.setBackgroundImage(source, canvas.renderAll.bind(canvas)); 

It works fine, but now mine

 canvas.toDataURL('png') 

stops working.

And also cleaning the canvas does not clear the background image. Could you explain where this is happening.

The code below works fine until I add a background image.

 document.getElementById('save').onclick = function() { window.open(canvas.toDataURL('png')); } 

also:

 canvas.clear(); 

The code does not clear the background image.

+4
source share
1 answer

var canvas = window._canvas = new fabric.Canvas ('c');

 canvas.setBackgroundImage(document.getElementById('img1').src, canvas.renderAll.bind(canvas)); document.getElementById('dataurl').addEventListener('click', function () { window.open(canvas.toDataURL()); }); 
0
source

Source: https://habr.com/ru/post/1497728/


All Articles