如何将二进制数据转换为reactjs中的图像 [英] how to convert the binary data to image in reactjs

查看:556
本文介绍了如何将二进制数据转换为reactjs中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将图像插入数据库,而且我从数据库到服务器接收图像并反应,但在我的反应中我收到它有二进制数据。
,但我如何将二进制数据转换为图像in react。

i have inserted an image to database and also i am receiving the image from database to server and to reactjs but in my react i am receiving it has binary data. but how do i convert the binary data to image in react.

class Pre extends React.Component{
  constructor(props){
    super(props);
    this.state={
      post:[]
    };

  }


componentDidMount(){
   let self = this;
  axios.get('http://localhost:8080/images')
  .then(function(data) {
      //console.log(data);
      self.setState({post:data.data});
      });
  }


  render(){

console.log(this.state.post);
    return(
    <div className="w3-container">


    <p className="addboard"> <Link className="linkpre"  to="/createstudent I">
      <button className="addbutton" type="button"><h1>+</h1></button></Link></p>


      {this.state.post}

)}
)}

</div>

    );
  }
}
export default Pre;


推荐答案

将二进制数据转换为图像与<$无关c $ c> ReactJS ,如果您有二进制数据,则将其转换为如下图像:

Converting binary data into image is not related to ReactJS, If you have the binary data then convert it into image like this:

<img src={`data:image/jpeg;base64,${binary_data}`} />

这篇关于如何将二进制数据转换为reactjs中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆