html5 - Is there no EASY way to enable the user the save the canvas? -
i've tried doing few hours, , i've tried every solution find both on stackoverflow , on other sites, without success.
the remarkable thing every solution or @ least distinctly different 1 another. , wc3schools , sites seem have no default way of solving whatsoever.
i have simple html-document body:
<body onload="draw();"> <canvas id="canvas1" width="500" height="500"></canvas> </body>
and js-document:
// javascript document function draw() { var canvas1 = document.getelementbyid('canvas1'); if(canvas1.getcontext) { var ctx = canvas1.getcontext('2d'); //here's lot of drawing i've removed make that's relevant more readable. } }
so i'm working with, , u can see i've removed of code drawing on canvas since code shouldn't necessary know save canvas (please tell me if is, though).
i don't care format i'm saving in or how (by clicking on button have implement/by right-clicking on canvas/other solutions), want know how in simplest possible way!
i managed accomplish in quite simple way after all. simple code needed enable user right-click on canvas , saving it, other picture. not simple implement, think it's desirable solution since it's way save pictures on internet.
var saveimage = canvas1.todataurl("image/png").replace("image.png", "saveimage/octet-stream"); window.location.href = saveimage;
"canvas1" name of canvas want save, , "image/png" has nothing code default name replace "saveimage/octet-stream", canvas in case.
i can't explain in detail code does, works!
Comments
Post a Comment