Part of my app includes html5 photo editing using a mixture of standard 2d context canvases and webGL.
Anyway, I am saving \'undo\' states while the user is manipula
getImageData() takes more memory than toDataURL()
widthOfImage * heightOfImage * 4, for example imageData length of image with dimensions 100 is var imageDataArrayLenth = 100 * 100 * 4 = 40 000 (bytes);Conclusion: Better way is to use BLOB (info).
//Example of using blob with objectURL
var canvas = document.getElementById("canvas");
canvas.toBlob((blob) => {
let img = new Image();
img.onload = () => URL.revokeObjectURL(img.src); // no longer need to read the blob so it's revoked
img.src = URL.createObjectURL(blob);
document.body.appendChild(img);
});