[英]How can I save my HTML5 canvas screen as a png image to a specific folder of my project with only pure javascript or jQuery?
This is what I have found and used so far for saving the image. 这是我迄今为止发现和使用的用于保存图像的内容。 This function perfectly taking the screenshot and opens the image in a new window location.
此功能完美地截取屏幕截图并在新窗口位置打开图像。 But I want to save the png image file to a specific folder of the project temporarily so that later on I can retrieve the image from that folder.
但我想暂时将png图像文件保存到项目的特定文件夹中,以便稍后我可以从该文件夹中检索图像。 This is my JS function:
这是我的JS功能:
function saveImage()
{
var canvasScreen = document.getElementById("paintCanvas");
var myImage;
if (canvasScreen.getContext)
{
ctx = canvasScreen.getContext("2d");
myImage = canvasScreen.toDataURL("image/png");
}
window.location.href = myImage;
}
This is the HTML part: 这是HTML部分:
<canvas id="paintCanvas" style="width: 100%; height: 100%;"><
/canvas>
I have already tried FileSaver.js ( https://github.com/eligrey/FileSaver.js ) but not succeeded. 我已经尝试过FileSaver.js( https://github.com/eligrey/FileSaver.js )但没有成功。 I have searched my solutions but came with nothing that works properly.
我已经搜索了我的解决方案,但没有任何正常工作。 I need this for HTML based mobile app.
我需要这个基于HTML的移动应用程序。 Please can anyone give me some clear idea or anything that you faced similar?
任何人都可以给我一些明确的想法或任何你遇到的类似的东西吗? Thanks in advance :)
提前致谢 :)
You can't. 你不能。 JavaScript does not have access to your local file system.
JavaScript无权访问您的本地文件系统。 It's all sandboxed for security reasons.
出于安全考虑,它都是沙箱。
You can send it to server and invoke a save-as from there (as you can do on client side as well, except for in IE), or use one of the many APIs for things like Dropbox , Google Drive etc. (or make a custom native application for the platform) which you integrate for synchronization on your local system in advance. 您可以将其发送到服务器并从那里调用保存(如同在客户端一样,除了在IE中),或者使用Dropbox , Google Drive等许多API中的一个(或者make平台的自定义本机应用程序,您可以提前集成以在本地系统上进行同步。
There is no way around it unfortunately. 不幸的是,没有办法绕过它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.