简体   繁体   English

Uncaught SecurityError:无法在'CanvasRenderingContext2D'上执行'getImageData':画布已被跨源数据污染

[英]Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data

I am getting this error in Chrome and Opera Browsers: 我在Chrome和Opera浏览器中收到此错误:

Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.

The code is working fine in Internet Explorer, Mozilla Firefox, and Safari. 代码在Internet Explorer,Mozilla Firefox和Safari中运行良好。 But I need to fix it in Chrome and Opera. 但我需要在Chrome和Opera中修复它。 Please help me to find a solution to fix this problem? 请帮我找一个解决方案来解决这个问题?

I am getting this error at this line 我在这一行得到了这个错误

imgData = ctx.getImageData(x1,y1,w,h);

May be this will help, as you have mentioned cross origin so try this, 可能这会有所帮助,因为你已经提到了交叉起源所以试试这个,

 var UimageObj = new Image();

crossOrigin has to be set to enable the canvas data to be saved.The source image should have access-control-allow-origin set to * or a chosen domain 必须设置crossOrigin以保存画布数据。源图像应将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;

Hope it helps. 希望能帮助到你。

When you load your html file from disk using: file://path/to/your/file.html , then Google Chrome and Opera will raise error at line including: imgData = ctx.getImageData(x1,y1,w,h); 使用: file://path/to/your/file.html从磁盘加载html文件时,谷歌Chrome和Opera将引发错误,包括: imgData = ctx.getImageData(x1,y1,w,h);

Solution is simple: start web server (apache, nginx) put your html file somewhere at web server and load your html file from: http://localhost/somewhere/file.html 解决方案很简单:启动Web服务器(apache,nginx)将您的html文件放在Web服务器的某处并从以下位置加载您的html文件: http://localhost/somewhere/file.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 控制台日志:Uncaught SecurityError:无法在'CanvasRenderingContext2D'上执行'getImageData':画布已被跨源数据污染 - Console Log: Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data 无法执行'getImageData' - 画布已被跨源数据污染 - Failed to execute 'getImageData' - The canvas has been tainted by cross-origin data 未捕获的SecurityError:无法在“ CanvasRenderingContext2D”上执行“ getImageData”: - Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': 当我尝试使用getImageData时,如何解决“画布已被跨域数据污染”。 - How to solve “ The canvas has been tainted by cross-origin data.” when I try to use getImageData 如何修复 getImageData() 错误画布已被跨域数据污染? - How to fix getImageData() error The canvas has been tainted by cross-origin data? 画布已被跨源数据污染 - The canvas has been tainted by cross-origin data 画布受到跨源数据工作的污染 - canvas has been tainted by cross-origin data work around 未捕获的类型错误:无法在“CanvasRenderingContext2D”上执行“getImageData”:提供的双精度值是非有限的 - Uncaught TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The provided double value is non-finite 错误:未捕获(承诺中)DOMException:无法在“CanvasRenderingContext2D”上执行“getImageData”:源高度为 0 - Error: Uncaught (in promise) DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source height is 0 无法从画布获取图像数据,因为画布已被跨源数据污染 - Unable to get image data from canvas because the canvas has been tainted by cross-origin data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM