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

时间:2021-01-15 20:27:07

I'm using the base-64 npm but how can it's returning random characters. Is there any way I can decode a string and product a png image file?

我使用的是基本-64 npm,但它如何能够返回随机字符。有什么方法可以解码字符串并产生png图像文件吗?

1 个解决方案

#1


0  

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} />

#1


0  

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} />