我在 Chrome 和 Opera 浏览器中遇到这个错误:
Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
该代码在 Internet Explorer、Mozilla Firefox 和 Safari 中运行良好。但我需要在 Chrome 和 Opera 中修复它。请帮我找到解决此问题的方法?
我在这一行收到这个错误
imgData = ctx.getImageData(x1,y1,w,h);
最佳答案
这可能会有所帮助,因为您已经提到交叉来源,所以试试这个,
var UimageObj = new Image();
必须设置 crossOrigin 才能保存 Canvas 数据。源图像应将 access-control-allow-origin
设置为 *
或选择的域
UimageObj.crossOrigin = 'anonymous'; // crossOrigin attribute has to be set before setting src.If reversed, it wont work.
UimageObj.src = obj_data.srcUser;
希望对您有所帮助。
关于javascript - 未捕获的安全错误 : Failed to execute 'getImageData' on 'CanvasRenderingContext2D' : The canvas has been tainted by cross-origin data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26688168/