Display image from blob using javascript and websockets

后端 未结 6 1371
春和景丽
春和景丽 2020-11-29 22:05

I\'m currently working on a WebSocket application that is displaying images send by a C++ server. I\'ve seen a couple of topics around there but I can\'t seem to get rid of

6条回答
  •  悲&欢浪女
    2020-11-29 22:28

    Thanks to the other answers, I managed to receive a jpeg image by websocket and display it in a new window :

    socket.binaryType = "arraybuffer";                 
    socket.onmessage = function (msg) 
                   {    var bytes = new Uint8Array(msg.data);
                        var blob = new Blob([bytes.buffer]);
                        window.open(URL.createObjectURL(blob),'Name','resizable=1');
                    };
    

提交回复
热议问题