Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在reactjs中将二进制数据转换为图像_Javascript_Reactjs - Fatal编程技术网

Javascript 如何在reactjs中将二进制数据转换为图像

Javascript 如何在reactjs中将二进制数据转换为图像,javascript,reactjs,Javascript,Reactjs,我已经向数据库插入了一个图像,并且我正在从数据库接收到服务器和reactjs的图像,但在react中,我接收到的是二进制数据。 但是如何将二进制数据转换为react中的图像呢 class Pre extends React.Component{ constructor(props){ super(props); this.state={ post:[] }; } componentDidMount(){ let self = this;

我已经向数据库插入了一个图像,并且我正在从数据库接收到服务器和reactjs的图像,但在react中,我接收到的是二进制数据。 但是如何将二进制数据转换为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;
类预扩展React.Component{
建造师(道具){
超级(道具);
这个州={
职位:[]
};
}
componentDidMount(){
让自我=这个;
axios.get()http://localhost:8080/images')
.then(功能(数据){
//控制台日志(数据);
self.setState({post:data.data});
});
}
render(){
console.log(this.state.post);
返回(

+

{this.state.post} )} )} ); } } 导出默认预处理;
将二进制数据转换为图像与
ReactJS
无关,如果您有二进制数据,请将其转换为图像,如下所示:

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

给定的方法是正确的

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

如果图像未渲染,请检查二进制字符串,如果数据:image/jpeg;base64已经存在,那么请直接使用{binary_data}。像

<img src={binary_data} />

不为我工作,我仍然有这个���� 在我的控制台中,图像不显示