Serialize canvas content to ArrayBuffer and deserialize again

后端 未结 3 1742
囚心锁ツ
囚心锁ツ 2021-01-02 02:27

I have two canvas, and I want to pass the content of canvas1, serialize it to an ArrayBuffer, and then load it in canvas2. In the future I will send the canvas1 content to t

3条回答
  •  耶瑟儿~
    2021-01-02 02:51

    Create an ArrayBuffer and send it into to the Uint8Array constructor, then send the buffer using websockets:

    var img1 = context.getImageData(0, 0, 400, 320);
    var data=img1.data;
    var buffer = new ArrayBuffer(data.length);
    var binary = new Uint8Array(buffer);
    for (var i=0; i

    [ Previous answer using canvas.toDataURL removed ]

提交回复
热议问题