Is it more beneficial to use a canvas element as a buffer for the image or is it more beneficial to use an img element as a buffer? is the closest thing to what I'm asking except the use case is slightly different. Currently I receive a file, for example:
let file=document.getElementById("input").files[0];
Then using URL.createObjectURL(file);
it can be injected into the src
attribute of an <img />
.
My feeling is that using a canvas instead and drawing from the the file blob, would use less memory. Except it seems that in most examples an image is still used as a go-between.
Ex.
let image = document.getElementById("image");
let canvas = document.getElementById("canvas");
canvas.drawImage(image,0,0);
image.parentNode.deleteChild(image);
In this example I'm using DOM which is slow (not that speed matters in this case) I would likely use a temporary image object like everyone else.
The question is if going the extra step and putting the data into the canvas would be at all ever beneficial or does the browser do some kind of optimization where the src blob url is minimized or removed in some way to save memory?
As a sub question if I did want it in a canvas after all to do image processing or something is there a more efficient way of getting a file into a canvas?