How to get a picture of my canvas

I am developing a small application using javascript, using this, I can draw on canvas. I want to know How to get a snapshot of my canvas and send it another one,

using javascript or any other server language. please help me .thanks.

+3
source share
4 answers

You can get the PNG image of the canvas as a data URL using the toDataURL method :

canvas.toDataURL(); // => data:...
+4
source

Take a look at this tutorial, it will show how to take a picture of your canvas and send it to your server using AJAX.

+2

Canvas2Image, HTML 5 .

+1

:

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

This will lead to a change in the location of the browser to a data URL containing PNG of the contents of the canvas, which the browser will offer to save (by changing the forces like mime, otherwise the browser will display only PNG.)

+1
source

Source: https://habr.com/ru/post/1757331/


All Articles