简体   繁体   中英

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,

using javascript or any other server side language. 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.

Send Canvas Content to Server

您可以使用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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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