简体   繁体   English

将base64字符串(png文件)解码回图像

[英]Decoding a base64 string (png file) back to an Image

I'm using the base-64 npm but how can it's returning random characters. 我正在使用base-64 npm,但它如何返回随机字符。 Is there any way I can decode a string and product a png image file? 有什么办法可以解码字符串并生成png图像文件?

If you are using React create a component like-so: 如果您使用的是React,请创建类似这样的组件:

class Base64Image extends React.Component{
  render() {
     return <img
       src={"data:image/jpeg;" + 
         this.props.imageBase64String} 
     />
  }
}

`` ``

To use the component, Assuming you have a base64Image variable: 要使用该组件,假设您有一个base64Image变量:

<Base64Image imageBase64String={base64Image} />

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

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