To transform binary image data (e.g. from a file input) into a canvas image source, createImageBitmap or Image.decode can be used.
Is there a cancellable alternative to these methods?
I want to render images from a multiple file input
to a canvas
element, one at a time. My current approach causes severe delays, if additional decode operations are started while the previous ones still run (I am only interested in the result of the most recent one).
I found out that Image.decode
can be cancelled in some browsers, by reassinging the image src
. However, this does not work universally (e.g. not in Firefox).
I am open to use third party libraries, as long as they are performant (WebAssembly) and free and if they at least support the most basic image formats like JPEG and PNG.
Edit
To clarify things, I created a Codepen: https://codepen.io/Tims777/pen/bGxvgBQ
Just select a bunch (100+) of large (~20MP) JPEGs and hold down the up button for a while to torture your CPU.