简体   繁体   English

如何使用纯javascript或jQuery将我的HTML5画布屏幕作为png图像保存到我项目的特定文件夹中?

[英]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中),或者使用DropboxGoogle Drive等许多API中的一个(或者make平台的自定义本机应用程序,您可以提前集成以在本地系统上进行同步。

There is no way around it unfortunately. 不幸的是,没有办法绕过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将html2canvas图像保存到我的项目图像文件夹中? - How to save html2canvas image to my project images folder? 使用javascript将画布另存为PNG图像在特定文件夹中 - Save canvas as PNG image in specific folder with javascript 将PNG画布图像保存到HTML5存储(JAVASCRIPT)? - Save PNG Canvas Image to HTML5 Storage (JAVASCRIPT)? 如何使用纯JavaScript和HTML5压缩画布图像并调整其大小? - How to compress and resize canvas image with pure javascript and HTML5? 使用html2canvas保存图像-纯Javascript - Save image with html2canvas - Pure Javascript 如何提高Html5画布的路径质量? - How can i improve my Html5 Canvas pathing Quality? 使用toDataURL(“image / png”)时如何捕获HTML5 Canvas的背景? - How can I capture the background of HTML5 Canvas when using toDataURL(“image/png”)? 如何使用(仅)Javascript将HTML Canvas保存为命名.PNG - How to save HTML Canvas as a named .PNG using (only) Javascript "在 HTML5 Canvas 和 Javascript 中跟随我的图像移动轨迹" - Moving trail after my image in HTML5 Canvas & Javascript jQuery,PHP-用HTML5拍摄图片,将其保存到画布中,将该画布获取为图像,然后将其发布到服务器中的文件夹中 - jQuery, PHP - Take a picture with HTML5, save it into a canvas, get that canvas to an image and post it in a folder in the server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM