canvas:Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canv...

image

原因:

canvas绘制图片,由于浏览器的安全考虑,如果在使用canvas绘图的过程中,使用到了外域的图片资源,那么在toDataURL()时会抛出安全异常

解决方案:


var img = new Image();

img.setAttribute('crossOrigin', 'anonymous')

img.src = "https://www........"

img.onload = () => {

    canvas.getContext('2d').drawImage(img , 0, 0, canvas.width, canvas.height);

}

你可能感兴趣的:(canvas:Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canv...)