canvas 绘制跨域图片,导出为图片的时候会出现Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. 
解决方案
var image = new Image();
image.crossOrigin = '';//重点设置跨域
image.onload = function (e)
{
$('#myCanvas').attr('width', this.width);
$('#myCanvas').attr('height', this.height);
ctx.drawImage(this, 0, 0, this.width, this.height, 0, 0, this.width, this.height)
}
image.src ='IMGURL'
//导出为png图片
var exportImg = cvs.toDataURL("image/png", 1);
$('#imgs').attr('src', exportImg);//设置src为base64的图片设置头部可跨域
header("Access-Control-Allow-Origin: *");
参考资料:https://developer.mozilla.org/zh-CN/docs/Web/HTML/CORS_enabled_image
本文著作权归作者 [ admin ] 享有,未经作者书面授权,禁止转载,封面图片来源于 [ 互联网 ] ,本文仅供个人学习、研究和欣赏使用。如有异议,请联系博主及时处理。
