admin管理员组文章数量:1429728
I had created shapes on html 5 canvas using kineticjs library. Now i want to save the canvas as an image on my local system harddrive. Pls tell me how can i achieve it by using KineticJS library.
I had created shapes on html 5 canvas using kineticjs library. Now i want to save the canvas as an image on my local system harddrive. Pls tell me how can i achieve it by using KineticJS library.
Share Improve this question asked Feb 25, 2013 at 8:40 PGBPGB 991 silver badge9 bronze badges 1- 1 Would HTML5 localStorage be sufficient or does it have to be a real file in the users filesystem? – Philipp Commented Feb 25, 2013 at 12:14
1 Answer
Reset to default 3After selecting the canvas (using something like document.getElementById I guess), you should be able to call the following to convert the canvas into a dataURL.
Once you've got that URL, open it in another browser window and do a standard Right Click->Save Image As, and save it as a JPG/PNG/etc.
var canvas = document.getElementById("mycanvas");
var img = canvas.toDataURL("image/png");
Whether or not you're able to save an image to the drive programmatically, I'm not sure, although I'd highly doubt it due to security constraints.
For more information regarding programmatically accessing the File System, check out this HTML5 FileSystem reference site.
http://www.html5rocks./en/tutorials/file/filesystem/
For more information regarding retrieving a dataURL for a KinectJS Stage canvas element, see the below snippet / url.
<script>
stage.toDataURL({
callback: function(){
// do something with the data url
},
mimeType: 'image/jpeg',
quality: 0.5
});
</script>
http://www.html5canvastutorials./kineticjs/html5-canvas-stage-data-url-with-kineticjs/
本文标签: javascriptSaving the html 5 canvas image on local harddriveStack Overflow
版权声明:本文标题:javascript - Saving the html 5 canvas image on local harddrive - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745550727a2662931.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论