How to save an image Canvas in PNG or JPG format? | Sololearn: Learn to code for FREE!

0

How to save an image Canvas in PNG or JPG format?

I have made ships with HTML5 and JS but I want to save the results in PNG format, how do I do . . . Traducido de español a inglés por traductor de Google si consigues un error por favor reportelo.

10/11/2020 12:54:28 AM

Daniel Briceño

10 Answers

New Answer

+2

You will have to open canvas image in your browser. I meant that you have to open your HTML in your browser. Then you will have to right click on your drawing. And click on save image. This will download the image. After saving THIS if u want to get in any other format. You can convert that photo. Hope this helps😊😊

+2

This solution allows you to change the name of the downloaded file: HTML: <a id="link"></a> JAVASCRIPT: var link = document.getElementById('link'); link.setAttribute('download', 'MintyPaper.png'); link.setAttribute('href', canvas.toDataURL("image/png").replace("image/png", "image/octet-stream")); link.click();

+1

I didnt understand Daniel Briceño

+1

No need to use onmoveevent

0

thank you very much.😁

0

I have a project https://code.sololearn.com/WzcN09FKLgzq/?ref=app

0

and I want to know how to save the image but your answer does not help me. Because I use a mobile device and the event: onmousemove () doesn't allow me that option. And he has another idea.

0

I can use the onclick event and on the cell phone it would give me the same results but not on the pc. Well, on the pc it would have very different results

0

You can use canvas.toDataUrl(); function

0

thanks I will try