Problems with toDataUrl

Asked

Viewed 28 times

2

I am trying to export to a text file the contents of a canvas with toDataUrl(), but I’m getting this mistake:

Domexception: Failed to execute 'toDataURL' on 'Htmlcanvaselement': Tainted canvases may not be Exported

I did some research and discovered that it is not possible to use the toDataUrl with images of "cross" origins, but the problem is that my image is local.

This is the current code:

const cnv = document.querySelector('canvas');
const ctx = cnv.getContext('2d');

const img = new Image;
img.src='./img/mydraw.png';

ctx.drawImage(img,0,0,300,140,0,0,300,140);
 
var image = cnv.toDataURL();
 
var blob = new Blob([image]);
saveAs(blob,'image.txt')
  • 1

    What is the absolute path of the image?

  • When you say the image is "local" is localhost, file, some IP, or you tested it on a specific domain?

  • The image is localhost

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.