How to save html2canvas image into System Folder in jquery

Ram

I have a form with id="form1" inside this form i have a graph.Now i am using html2canvas to get the image of this form1.Here is my code..

<script type="text/javascript">

      $(document).ready(function () {
          $('#add_button').click(function () {
              alert("hiii");
              $('form1').html2canvas();
              var queue = html2canvas.Parse();
              var canvas = html2canvas.Renderer(queue, { elements: { length: 1} });
              var img = canvas.toDataURL();
              window.open(img);
              alert("Hello");
          });
      });

  </script>

<form id="form1" runat="server">
<div style="padding-left:150px">
  <asp:Literal ID="FCLiteral1" runat="server"></asp:Literal>
</div>
<div style="padding-left:350px"><b>Demo</b></div>
</form>

 <input type="submit" id="add_button" value="Take Screenshot Of Div" " />

So my question is how can i save this image into my system hardisk..Please help me.

Guilherme Nascimento

System hardisk? I did not understand, server or client?

CLIENT

If you want the user to download the image automatically, you will need to modify the Data URI scheme

Try this:

Add in css

#myHideFrame {
    position: absolute;
    top: -9999px;
    width: 1px;
    height: 1px;
}

Add in Javascript

var img = canvas.toDataURL();
var frame = document.getElementById("myHideFrame");
if(!frame) {
    frame = document.createElement("iframe");
    frame.id = "myHideFrame";
    document.body.appendChild(frame);
}
frame.src = img.replace(/^data[:]image\/(png|jpg|jpeg)[;]/i, "data:application/octet-stream;");

Unfortunately this example does not show the name, for this you will have to do something like this (user need click in link):

var img = canvas.toDataURL();
var link = document.createElement("a");
link.download = "photo.png"; //Setup name file
link.href = img.replace(/^data[:]image\/(png|jpg|jpeg)[;]/i, "data:application/octet-stream;");
document.body.appendChild(link);

SERVER

If you want to save on the server then you need to use Ajax, example with Jquery:

Javascript file:

var img = canvas.toDataURL().replace(/^data[:]image\/(png|jpg|jpeg)[;]base64,/i, "");
$.ajax({
    "type": "POST",
    "url": "upload.aspx/UploadImage",
    "data": { 
        "imageData": img //Send to WebMethod
    }
}).done(function(o) {
    console.log(["Response:" , o]); 
});

Your upload.aspx.cs file need:

...
[WebMethod()]
public static void UploadImage(string imageData)
{
    string fileNameWitPath = "custom_name.png";
    using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
    {
        using (BinaryWriter bw = new BinaryWriter(fs))
        {
            byte[] data = Convert.FromBase64String(imageData);//convert from base64
            bw.Write(data);
            bw.Close();
        }
    }
}
...

See details: http://www.dotnetfunda.com/articles/show/1662/saving-html-5-canvas-as-image-on-the-server-using-aspnet

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to save html2canvas image into System Folder in jquery

From Dev

How to save image canvas to folder?

From Dev

How to save an image in a folder?

From Dev

Codemirror & html2canvas: Save iFrame as Image

From Dev

how to use html2canvas to save a div

From Java

How to save image to camera folder in Android Q?

From Dev

How to save image to user folder in django?

From Dev

how to upload image in database save in folder?

From Dev

How to auto save highcharts as image in specific folder

From Dev

How to Save Image to Application Folder from UIImagePickerController?

From Dev

How to save canvas image to mySQL without php, jquery

From Dev

How to save canvas image to mySQL without php, jquery

From Dev

How to save a rotated image with jQuery?

From Dev

How can I download content of div using html2canvas and FileSaver in the dowllaods folder instead of in the browser?

From Dev

JQuery replace image with Base64 (html2canvas no proxy)

From Dev

How to save img to user's local computer using HTML2canvas

From Dev

How to save img to user's local computer using HTML2canvas

From Dev

Image Manipulation - How do I save original, resize & save in folder A and make thumbnail & save in folder B

From Dev

Save image into an output folder

From Dev

How to download current screen as PDF and Image using html2canvas JS?

From Dev

How to download current screen as PDF and Image using html2canvas JS?

From Dev

html2canvas not capturing image

From Dev

html2canvas crop image on click

From Dev

html2canvas not taking capture of image

From Dev

html2canvas capturing div image

From Dev

html2canvas crop image on click

From Dev

How read image file in javascript and save it to different folder?

From Dev

How can I save Image files in in my project folder?

From Dev

How to save hd image in from alasset to documents folder in ios

Related Related

  1. 1

    How to save html2canvas image into System Folder in jquery

  2. 2

    How to save image canvas to folder?

  3. 3

    How to save an image in a folder?

  4. 4

    Codemirror & html2canvas: Save iFrame as Image

  5. 5

    how to use html2canvas to save a div

  6. 6

    How to save image to camera folder in Android Q?

  7. 7

    How to save image to user folder in django?

  8. 8

    how to upload image in database save in folder?

  9. 9

    How to auto save highcharts as image in specific folder

  10. 10

    How to Save Image to Application Folder from UIImagePickerController?

  11. 11

    How to save canvas image to mySQL without php, jquery

  12. 12

    How to save canvas image to mySQL without php, jquery

  13. 13

    How to save a rotated image with jQuery?

  14. 14

    How can I download content of div using html2canvas and FileSaver in the dowllaods folder instead of in the browser?

  15. 15

    JQuery replace image with Base64 (html2canvas no proxy)

  16. 16

    How to save img to user's local computer using HTML2canvas

  17. 17

    How to save img to user's local computer using HTML2canvas

  18. 18

    Image Manipulation - How do I save original, resize & save in folder A and make thumbnail & save in folder B

  19. 19

    Save image into an output folder

  20. 20

    How to download current screen as PDF and Image using html2canvas JS?

  21. 21

    How to download current screen as PDF and Image using html2canvas JS?

  22. 22

    html2canvas not capturing image

  23. 23

    html2canvas crop image on click

  24. 24

    html2canvas not taking capture of image

  25. 25

    html2canvas capturing div image

  26. 26

    html2canvas crop image on click

  27. 27

    How read image file in javascript and save it to different folder?

  28. 28

    How can I save Image files in in my project folder?

  29. 29

    How to save hd image in from alasset to documents folder in ios

HotTag

Archive