img使用canvas转为base64跨域问题
在使用 canvas 将 img 的 src 地址转换为 base64 调用 canvas.toDataURL() 时,遇到跨域问题并报错如下Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. at img.onload解决方案:在 onload 之前添加 crossOrigin 参数 var img = new Image();
img.src = src;
img.crossOrigin = '';
img.onload = function () {
// todo
}具体参考大佬方案
Ginkgo
一个今天胜过两个明天。
30
文章
0
评论
5
分类