Convert canvas to image

From LemonWiki共筆
Jump to navigation Jump to search

Convert HTML5 canvas to image

var canvas = document.getElementById('dom_id'),
    dataUrl = canvas.toDataURL(),
    imageFoo = document.createElement('img');
    
imageFoo.src = dataUrl;

// Style your image here
imageFoo.style.width = '800px';
imageFoo.style.height = '600px';

// After you are done styling it, append it to the BODY element
// document.body.appendChild(imageFoo);

var url = 'data:application/octet-stream' + dataUrl;
window.open(url);

Testing result:

References: