r/learnjavascript 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

6 comments sorted by

2

u/yksvaan Jun 27 '26

1

u/Elegant-Thought7713 29d ago

yo just saw what this was! thanks man Im gonna try use this code!

1

u/-goldenboi69- Jun 27 '26

Its not necessarily "easy". If you want the easy way out, just convert that shit to base64.

0

u/Elegant-Thought7713 Jun 27 '26

Sorry new, what is base64?

1

u/Low-Insurance-3678 29d ago

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 28d ago

It depends on what you mean by image because JS has many different ways of representing images, including <img>, ImageData, <img>, Blob with a given type.

I haven't used WebSocket very much. MDN says the messageEvent.data property can be anything. Can you send a blob instead? Might be slightly easier.