本文介绍了未捕获的SecurityError:无法在'CanvasRenderingContext2D'上执行'getImageData':画布已被跨原始数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Chrome和Opera浏览器中收到此错误:
I am getting this error in Chrome and Opera Browsers:
Uncaught SecurityError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The canvas has been tainted by cross-origin data.
该代码在Internet Explorer,Mozilla Firefox和Safari中正常工作。但我需要修复它在Chrome和Opera。请帮助我找到解决此问题的解决方案?
The code is working fine in Internet Explorer, Mozilla Firefox, and Safari. But I need to fix it in Chrome and Opera. Please help me to find a solution to fix this problem?
我在此行收到此错误
imgData = ctx.getImageData(x1,y1,w,h);
推荐答案
原始,所以试试这个,
var UimageObj = new Image();
crossOrigin必须设置为启用画布数据保存。 c $ c>访问控制允许源设置为 *
或所选域
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
UimageObj.crossOrigin = 'anonymous'; // crossOrigin attribute has to be set before setting src.If reversed, it wont work.
UimageObj.src = obj_data.srcUser;
希望它有帮助。
这篇关于未捕获的SecurityError:无法在'CanvasRenderingContext2D'上执行'getImageData':画布已被跨原始数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!