简体   繁体   English

如何通过js将二进制代码的图像从api转换为png

[英]how can I turn verify image of binary code from api to png by js

I try to put the verify image api into browser straightly, any I found code like below picture: enter image description here 我尝试将验证图像api直接放入浏览器,找到的任何代码如下图所示: 在此处输入图像描述

And use this code with 'data:image/png;base64' then I can get this verify image picture, and also I try to put api url into src of element ,but I still willing to get the response data and show it so that server side can do less, now the issue is when I call this api request, I got response data like below picture: enter image description here 并将此代码与'data:image / png; base64'一起使用,我可以获取此验证图像图片,并且尝试将api url放入element的src中,但我仍然愿意获取响应数据并进行显示,以便服务器端可以做的更少,现在的问题是当我调用此api请求时,我得到了如下图所示的响应数据: 在此处输入图像描述

Something like gibberish! 有点像胡言乱语! Can anyone help me figure out?! 谁能帮我弄清楚吗?

I think, you should set xhr.responseType = "arraybuffer"; 我认为,您应该设置xhr.responseType = "arraybuffer"; in your xhr request and then make blob object 在您的xhr请求中,然后使blob对象

jsfiddle example jsfiddle示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM