createImageBitmap alternative on Safari

后端 未结 1 1893
北荒
北荒 2020-12-01 22:42

I\'d like to generate images in a bit of asm.js code running on a web worker. And I\'d like to regularly composite the latest state of that computation onto a user-visible 2

相关标签:
1条回答
  • 2020-12-01 23:12

    Is there some other way to turn a byte array into something you can feed to drawImage?

    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);
    }
    

    http://plnkr.co/edit/N0v1YQHQX2rdFfHcOKeR?p=preview

    0 讨论(0)
提交回复
热议问题