问题描述
我正在尝试在 React 配置文件类组件中显示图像。图像的格式是来自 SQL Server 的二进制格式,并以 varbinary 格式存储。这就是我转换图像的方式。
图像数据
Picture: {type: "Buffer",…}
data: [67,58,92,68,65,84,69,78,71,73,66,46,72,101,108,112,97,83,…]
type: "Buffer"
arrayBufferToBase64(buffer) {
var binary = '';
var bytes = [].slice.call(new Uint8Array(buffer));
bytes.forEach((b) => binary += String.fromCharCode(b));
return window.btoa(binary);
}
这就是我绑定图像的方式
let binaryImg = this.arrayBufferToBase64(this.props.courseDetail?.Picture?.data);
this.setState({picture : "data:image/jpeg;base64,"+binaryImg})
HTML 代码
<img src={"data:image/jpeg;base64,"+this.state.picture}/>
or <img src={this.state.picture}/>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)