gpt4 book ai didi

javascript - canvas.toDataURL 替代方案?

转载 作者:行者123 更新时间:2023-11-30 18:17:30 26 4
gpt4 key购买 nike

我正在尝试将 HTML5 Canvas 的内容转换为 png 图像。

问题是 Canvas 包含未在本地托管的图像,因此出现安全错误。

我没有在本地托管图像的选项,有没有其他方法可以捕获 Canvas 元素内的内容?

谢谢!

最佳答案

除非你能让你的图像资源 CORS 友好,否则不要。

https://developer.mozilla.org/en-US/docs/CORS_Enabled_Image#What_is_a_.22tainted.22_canvas.3F

Although you can use images without CORS approval in your canvas, doing so taints the canvas. Once a canvas has been tainted, you can no longer pull data back out of the canvas. For example, you can no longer use the canvas toBlob(), toDataURL(), or getImageData() methods; doing so will throw a security error.

编辑:当然,如果您不局限于纯 HTML5 方法,则可以使用一些 Flash/Crossdomain.xml 技巧,但这仍然假定您对提供图像的服务器有一定的控制权。

关于javascript - canvas.toDataURL 替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12905747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com