[英]Chrome: Tainted canvases may not be exported; Offline-only app
This question is similar, but not identical to many of the existing questions on this topic, including Tainted canvases may not be exported . 该问题与该主题上的许多现有问题相似,但并不完全相同,包括可能无法导出脏画布 。
I am writing an offline-only app that has to stay that way and cannot use a local web server. 我正在编写仅离线应用程序,该应用程序必须保持这种状态,并且不能使用本地Web服务器。 Is there any way to circumvent the CORS check on the canvas in order to copy the data back to the base image.
有什么方法可以规避画布上的CORS检查,以便将数据复制回基础图像。
Here is an example of the code I am trying: 这是我尝试的代码示例:
var c1 = document.getElementById("tmp1");
var ctx1 = c1.getContext('2d');
var tmpImg1 = document.getElementById("tmpimg1");
ctx1.drawImage(img1, 0, 0, 150, 150);
tmpImg1.src = c1.toDataURL();
The error message from Chrome is as follows: 来自Chrome的错误消息如下:
Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
未捕获到的SecurityError:无法在“ HTMLCanvasElement”上执行“ toDataURL”:可能无法导出污染的画布。
In an offline-only situation, what options are available that still have the same end result? 在仅脱机的情况下,哪些可用选项仍具有相同的最终结果?
You could specify all your img.src
as inline base64-encoded URLs. 您可以将所有
img.src
指定为内联base64编码的URL。
img.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAA ..."
This way all the imgs are local to your app and CORS is satisfied. 这样,所有img都在您的应用程序本地,并且满足CORS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.