S
S
SpeNch2021-02-11 18:38:55
Canvas
SpeNch, 2021-02-11 18:38:55

How to save the hole?

How to save a canvas canvas to a folder, as a png file

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-02-11
@SpeNch

const canvas = document.querySelector("#canvas"); // берём канвас
canvas.toBlob(blob => { //Переводим в блоб
            // Делаем специальную ссылку
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.style.display = 'none';
            a.href = url;
            a.download = "canvas.png"
            document.body.appendChild(a);
            // кликаем по ссылке
            a.click();
            //убираем
            window.URL.revokeObjectURL(url);
            a.remove();
        });

S
Stalker_RED, 2021-02-11
@Stalker_RED

I have a sketch

On lines 16-19, a downloader link is created and on line 32 it is attached to a button, or whatever you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question