canvas使用跨域的图片时,不加 image.crossOrigin = 'Anonymous'; 图片可以绘制,但是不能调用 toBlob(), toDataURL() 或 getImageData() 方法,调用它们会抛出安全错误。
Unable to get data URL. Failed to execute ‘toDataURL’ on ‘HTMLCanvasElement’: Tainted canvases may not be exported.
如果加上 image.crossOrigin = 'Anonymous'; 报错 Access to image at 'http://10.10.10.112/product/AVWT-154FESSA.png' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
问题的原因:是后端没有配置允许接受跨域
换下小写试试
image.setAttribute(‘crossorgin’,’anonymous’)
将image作为文件读取blob流,ctx.toBlob 试试
stackoverflow