我正在从Nodejs服务器接收绑定,现在需要显示图像。
我该如何实现?有什么方法可以将bindata转换为JPEG或任何其他格式?还是可以在服务器中将其转换然后发送该图像以作出反应?
这是我尝试item.Image.data.data
使用图片标签显示二进制数据()的方法:
<img src={item.Image.data.data} />
这是我的详细反应代码段:
componentDidMount(){
let self = this;
axios.get('http://localhost:8080/list')
.then(function(data) {
console.log(data);
self.setState({post:data.data});
});
}
<ul className="w3-ul w3-card-4 w3-light-grey">
{ this.state.post.map((item, index) => {
return (
<Link to="/displaylist" style={{ textDecoration: 'none' }} key={index}>
<li className=" w3-hover-green w3-padding-16" onClick={this.handleClick(item.Id)}>
<img src={item.Image.data.data} className="w3-left w3-circle w3-margin-right" width="60px" height="40px" />
<span>{item.Firstname}</span><br/><br/>
</li>
</Link>
)}
)}
</ul>
这是我的nodejs代码片段:
server.get('/list', function(req, res) {
databaseInterface.listStudent(function(err, students) {
var myJSON = students;
res.json(myJSON);
// You should see the newly saved student here
});
});
如果二进制数据表示为 base64 字符串:
// Base64 string data
const data = 'iVBORw0KGgoAAAANSUhEUgAAAFgAAABSCAYAAADQDhNSAAAABHNCSVQICAgIfAhkiAAAFN5JREFUeJztnHl0FFW+xz/VS3rLTkJ2EkICIWEzgICIw8Ao6KCo4zDKuM04bqjPJyLqoAj6VBREHcVtBnXUcUMU3BVUhFFQQJEQkwhJyJ6Qfe10ernzRzVFd9JJukOKd857+Z6Tc6qr7vKrb27d+t3f73tLSk1NFQxBNWj+tw34v44hglXGEMEqY4hglTFEsMoYIlhlDBGsMoYIVhlDBKuMIYJVhu6UdxgaTsSkGZjiRoBGg62umtZfDtFRcliV/szJaYSMHo8hKhZcLqxVpTQe2I2jpUmV/rrjlBGsMZpJ/fPtxJ27CI0+qMd1a3U5NdvepfLDN7A3N5xUX/rwSOJ/exkxZ1+MKTaxx3WXvYuqT96m6MXHcHV2nFRf/UE6FcEeXXAoEx95heBRY/st6+y0UrHlFUrfeg6nNbCb15rMjPjDDSRceCVao6nf8m2Fef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929P2enlYIn7qF2h//yrIHglIzg4zBEx5Fw4VVETj1L/vqqJNFVX0PrLznUf7eDum8+C/h7lb1BazITNXMew6bNJmT0eIKGxYAQWKtKadi7k4otvvUbg41TSvD/Rwx9oFllDBGsMoYIVhlDBKuMIYJVxhDBKmOIYJXxH4r7WLwgFoGBAAAAAElFTkSuQmCC'
const Example = ({ data }) => <img src={`data:image/jpeg;base64,${data}`} />
ReactDOM.render(<Example data={data} />, document.getElementById('container'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="container"></div>
如果您只有图片网址,则只需执行以下操作 :
const imageURL = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/React-icon.svg/1280px-React-icon.svg.png'
const Example = ({ imageURL }) => <img src={imageURL} width={100} />
ReactDOM.render(<Example imageURL={imageURL} />, document.getElementById('container'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="container"></div>
问题内容: 这是有效的.JPEG图像的二进制文件。 http://pastebin.ca/raw/2314500 我试图使用Python将二进制数据保存到图像中。 如何使用extjs 4将这些数据转换为可见的.JPEG图像? 我试过了,但是没有用。 问题答案: 需要将其转换为base64。 JS具有btoa()函数。 例如: 但是我认为您在pastebin中的二进制数据无效-jpeg数据必须以’f
问题内容: 我已经将图像插入数据库,并且我正在从数据库到服务器以及reactjs接收图像,但是在我的反应中,我接收到的图像具有二进制数据。但是我如何将二进制数据转换为图像中的反应。 问题答案: 将二进制数据转换为图像与无关,如果您拥有二进制数据,则将其转换为图像,如下所示:
问题内容: 在我的Android应用程序中。我从jpeg图像的代码中获取了二进制代码,如下所示。 该字符串s打印图像的二进制值。我的问题是如何将这种二进制格式转换为jpeg图像? 问题答案: 我不太确定你想要什么 如果要直接从流中创建-instance,则可以使用 它,然后在-instance中显示它: imageView.setImageBitmap(image); 如果要将基数2的字符串表示形
问题内容: 如何在Swift中将Int转换为UInt8?例。我想将数字22转换为0b00010110 问题答案: 您可以使用带有参数的初始化程序将十进制值转换为人类可读的二进制 表示形式 : 如果您愿意,也可以很容易地用任意数量的零填充它: 斯威夫特5
问题内容: 我一直在寻找如何从数据库中检索二进制数据。我的查询工作正常,因为它在SQL管理器中显示了二进制数据。 但是在Visual Studio 2010中,它只是向我显示,我个人认为这不是问题,但是如果我尝试检索它并将其存储在变量中,则它只是空的。只要与二进制数据无关,任何其他查询都可以工作… 而且我不想使用数据网格或其他任何东西,因为我只需要将其用作变量。 我知道这不是完整的代码,但这是出问
我有一个代码,其中矩阵hip_dir表示一个RGB图像。如果我检查它的形状,python返回(1080, 1920, 3)。如果我写 我得到保存在文件夹中的正确图像。然而,当我这样做的时候 我得到了同样的图像,黑色和白色(有一些蓝色像素,但是,使这更奇怪)。 如何正确使用imshow? 编辑: 使用命令cv2。cvtColor导致以下错误: Edit2:我发现发生这个错误的原因很简单,因为矩阵是n