Is there some other way to turn a byte array into something you can
feed todrawImage
?
You can post the ArrayBuffer
of Uint8ClampedArray
object to main thread; at main thread substitute using .putImageData()
for .drawImage()
. As indicated by @Kaiido, it is not necessary to create an ImageData
object at Worker
var imgBytes = new Uint8ClampedArray(buffer, offset);
postMessage(imgBytes.buffer, [imgBytes.buffer]);
at main thread
worker.onmessage = function(e) {
console.log(e.data); // `ArrayBuffer`
ctx.putImageData(new ImageData(new Uint8ClampedArray(e.data), width, height), 0, 0);
}