img使用canvas转为base64跨域问题

在使用 canvasimgsrc 地址转换为 base64 调用 canvas.toDataURL() 时,遇到跨域问题并报错如下

Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. at img.onload

67571-rse1if4af1b.png

解决方案:

在 onload 之前添加 crossOrigin 参数

 var img = new Image();
 img.src = src;
 img.crossOrigin = '';
 img.onload = function () {
   // todo
 }

具体参考大佬方案

版权属于:

Ginkgo

本文链接:

https://www.imao2.com/article/172.html(转载时请注明本文出处及文章链接)

Ginkgo

一个今天胜过两个明天。

31 文章
0 评论
5 分类

标签云