我有一个必须在本地运行的 HTML5 应用程序。当我运行应用程序并尝试在画布上加载图像时,在 Chrome 上我收到错误消息:
无法从画布获取图像数据,因为画布已被跨域数据污染
HTML 文档和本地文件夹中的图像。这是一个将分发给用户的应用程序,因此我无法运行本地服务器。它必须在 Chrome 上按原样运行...我已阅读有关此问题的答案,但它们都与与本地文件无关的 CORS 和跨组织策略有关...
这种情况的解决方案是什么?如何在 Chrome 本地加载画布上的图像?
编辑:这是引发错误的代码:
var canvas = Matach.createElement(false, "canvas", false, false);
var context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.globalCompositeOperation = 'source-over';
context.save();
context.drawImage(
item.img.img,
-item.img.width / 2,
-item.img.height / 2,
item.img.width,
item.img.height
);
context.restore();
res = context.getImageData(0, 0, canvas.width, canvas.height);