简体   繁体   English

如何保存从画布转换为本地文件夹的图像?

[英]how to save an image which is converted from a canvas in to my local folder?

For my javascript application i need to take the screen shot of every page in my ipad presentations, anyway i found a solution for that using html2canvas. 对于我的javascript应用程序,我需要对ipad演示文稿中的每个页面进行截屏,无论如何,我都使用html2canvas找到了解决方案。 Now i'm able to convert the html page to image but how can i save that in my presentations image folder using javascript? 现在,我可以将html页面转换为图像,但是如何使用javascript将其保存在演示文稿图像文件夹中?

Here is my javascript 这是我的javascript

html2canvas(document.body, 
{
  onrendered: function(canvas) 
{  
  var test = document.getElementsByClassName('test');    //finding the div.test in the page  
  $(test).append(canvas);                                //appending the canvas to the div
  var canvas = document.getElementsByTagName('canvas');     
  $(canvas).attr('id','test');                          //assigning an id to the canvas
  var can2 = document.getElementById("test");
  var dataURL = can2.toDataURL("image/png");            //converting the canvas to      image(PNG)      
  document.getElementById("image_test").src = dataURL;  //assigning the url to the image
  $(canvas).remove();                                   //removing the image
},logging:true,background: "#fff",
});

and here is my html 这是我的html

<div class="wrapper">
  <div class="container">
    <div class="test">
      <img src="" id="image_test">
    </div>
  </div>
</div>

Can anybody help me how can i save the image having the id "image_test" in my presentations images folder? 有人可以帮我如何在演示文稿图像文件夹中保存ID为“ image_test”的图像吗?

Thanks in advance. 提前致谢。

If you're saving the file on a server, you can link the user to the file page. 如果要将文件保存在服务器上,则可以将用户链接到文件页面。 otherwise, you can link to a "fake" path, based on the data 否则,您可以根据数据链接到“假”路径

eg: 例如:

function download(data){
    document.location = 'data:Application-octet-stream,'+
                         encodeURIComponent(data);
}

http://blogs.adobe.com/cantrell/archives/2012/01/how-to-download-data-as-a-file-from-javascript.html http://blogs.adobe.com/cantrell/archives/2012/01/how-to-download-data-as-a-file-from-javascript.html

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM