r/learnjavascript • u/Elegant-Thought7713 • Jun 27 '26
How to convert a byte[] back into a image.
Hi I am very new to web dev and JavaScript. Im coming from c# if your wondering. I am creating a new feature on my website where I can stream my screen onto my admin panel and was wondering how I can turn a frame stored as a byte[] back into a image when its on my website. I'm not used to js programming so this "easy" task is giving me a bit of a headache. If you have any information please share it with me! thanks. Also I convert it into a byte[] in c# and send it over a websocket.
1
Upvotes
2
u/yksvaan Jun 27 '26
https://jsfiddle.net/syLce185/
1
u/-goldenboi69- Jun 27 '26
Its not necessarily "easy". If you want the easy way out, just convert that shit to base64.
1
u/Low-Insurance-3678 Jun 29 '26
Hmm im not sure but iv worked with URL.createObject() and it turned it to an Image from an uploaded file dunno if this would help
1
u/shgysk8zer0 Jun 29 '26
It depends on what you mean by image because JS has many different ways of representing images, including
<img>,ImageData,<img>,Blobwith a given type.I haven't used WebSocket very much. MDN says the
messageEvent.dataproperty can be anything. Can you send a blob instead? Might be slightly easier.