Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  29] [ 3]  / answers: 1 / hits: 155731  / 13 Years ago, mon, november 14, 2011, 12:00:00

What are the different ways to save a canvas object?



In my research, I've found two approaches:



var data = canvas.toDataURL();
var prev = window.location.href;
window.location.href = data.replace(image/png, image/octet-stream);
window.location.href = prev;


Another way is to take a snapshot.



Are there other ways to do this?



Is it possible to customize the download filename?


More From » canvas

 Answers
18

The one way to save is exporting as an image... You already found this solution, and it's the best one i think ;)



    var canvas = document.getElementById(mycanvas);
var img = canvas.toDataURL(image/png);
document.write('<img src='+img+'/>');


You can use different image types. Change the mimetype in this function:



    canvas.toDataURL(image/jpeg);


An other way to save canvas data (into a PDF) is using the wkhtmltopdf Library



Cheers. Frank



frankneff.ch / @frankneff


[#89131] Saturday, November 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nicholas

Total Points: 188
Total Questions: 76
Total Answers: 103

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
nicholas questions
;