简体   繁体   English

如何获取我的画布快照

[英]How get snapshot of my canvas

I develop small application using javascript, using this I can draw on the canvas.I want to know, How get snapshot of my canvas and send it another one, 我使用javascript开发小应用程序,使用它我可以在画布上绘制。我想知道, 如何获取我的画布的快照并将其发送给另一个,

using javascript or any other server side language. 使用javascript或任何其他服务器端语言。 please help me.thanks. 请帮帮我。谢谢。

您可以通过toDataURL方法获取画布的PNG图像作为数据URL:

canvas.toDataURL(); // => data:...

Take a look at this tutorial, it shows how to take a snapshot of your canvas and send it to your server using AJAX. 看一下本教程,它展示了如何拍摄画布的快照并使用AJAX将其发送到您的服务器。

Send Canvas Content to Server 将Canvas内容发送到服务器

您可以使用Canvas2Image将HTML 5画布保存到文件以供下载。

I use the following: 我使用以下内容:

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

This causes the browser's location to change to a data-url containing a PNG of the canvas contents that the browser will then prompt to save (changing the mime-type forces that, otherwise the browser will just display the PNG.) 这会导致浏览器的位置更改为包含画布内容的PNG的数据URL,然后浏览器将提示保存(更改mime类型的力,否则浏览器将只显示PNG。)

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

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