Now generating canvas image blob asynchonrously.

This commit is contained in:
Marat Fayzullin 2023-02-22 16:48:24 -05:00
parent 49175ebcff
commit d81bb3fbf3
1 changed files with 15 additions and 12 deletions

View File

@ -98,19 +98,22 @@ function saveCanvas(canvas) {
var c = document.getElementById(canvas);
if (c == null) return;
// Create and click a link to the canvas data URL
var a = document.createElement('a');
a.href = c.toDataURL('image/png');
a.style = 'display: none';
a.download = canvas + ".png";
document.body.appendChild(a);
a.click();
// Convert canvas to a data blob
c.toBlob(function(blob) {
// Create and click a link to the canvas data URL
var a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.style = 'display: none';
a.download = canvas + ".png";
document.body.appendChild(a);
a.click();
// Get rid of the canvas data URL
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(a.href);
}, 0);
// Get rid of the canvas data URL
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(a.href);
}, 0);
}, 'image/png');
}
function zoomInOneStep() {