受污染的画布可能无法出口 [英] Tainted canvases may not be exported

查看:611
本文介绍了受污染的画布可能无法出口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将画布保存为img。我有这个功能:

I want to save my canvas to a img. I have this function:

function save() {
    document.getElementById("canvasimg").style.border = "2px solid";
    var dataURL = canvas.toDataURL();
    document.getElementById("canvasimg").src = dataURL;
    document.getElementById("canvasimg").style.display = "inline";
}

它给了我错误:


Uncaught SecurityError:无法在'HTMLCanvasElement'上执行'toDataURL':可能无法导出受污染的画布。

Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

我该怎么办?

推荐答案

出于安全考虑,您的本地驱动器被声明为其他域名 并且会污染画布。

For security reasons, your local drive is declared to be "other-domain" and will taint the canvas.

(这是因为您最敏感的信息可能在您的本地驱动器上!)。

(That's because your most sensitive info is likely on your local drive!).

在测试时尝试这些解决方法:

While testing try these workarounds:


  • 放置所有与页面相关的文件(.html,.jpg,.js ,.桌面上的css等(不在子文件夹中)。

  • Put all page related files (.html, .jpg, .js, .css, etc) on your desktop (not in sub-folders).

将图片发布到支持跨域共享的网站(如dropbox.com) )。确保将图像放在Dropbox的公共文件夹中,并在下载图像时设置交叉原点标记(var img = new Image(); img.crossOrigin =anonymous...)

Post your images to a site that supports cross-domain sharing (like dropbox.com). Be sure you put your images in dropbox's public folder and also set the cross origin flag when downloading the image (var img=new Image(); img.crossOrigin="anonymous" ...)

在开发计算机上安装Web服务器(IIS和PHP Web服务器都有免费版本,可以在本地计算机上很好地工作)。

Install a webserver on your development computer (IIS and PHP web servers both have free editions that work nicely on a local computer).

这篇关于受污染的画布可能无法出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆