Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

Decoding image in Javascript

I have basically made an api in flask the return png image from the server and the intresting thing is that I am returning that image by writing on the bytes io.But the problem is the JavaScript is displaying it in charcters that only aliens can understand. Here it is

`?PNG

? ??? IHDR??????????????|????>IDATx??X? ?0?S?!cN?)9?9??? ????[Q?KiXKbk"(Q?E?D?????2{?b>??????????S?g??9???U%=?Q?KbDE?笻? ????#§?JG?T'???E?????S?J??c?3v;B???N?hSh?y??????n??Q?~?}в#????D?s$b???%?A?????????=G(??????[L ???&?@??#?p???5??6?N????O89??????pr?0nD???U??????.?6????;??Z???2??g"??????PP|? &????G?k??-?~ti]sA????????/??????G?????IEND?B? script.js:39:13 Please anyone help me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is what happens if you try to console.logthe image's binary data. If your javascript is running in browser what you'd want to use is something like

<img src="data:image/png,[binary data you received]">

in order to show the image in your web page


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...