java base64转图片png格式
时间: 2023-11-15 15:57:44 浏览: 83
Base64转图片
5星 · 资源好评率100%
Java中可以使用Base64类将base64格式的字符串转换为图片。具体步骤如下:
1. 将base64字符串解码为字节数组。
2. 使用ImageIO类的read方法将字节数组转换为BufferedImage对象。
3. 将BufferedImage对象保存为png格式的图片文件。
以下是一个示例代码:
```
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Base64;
import javax.imageio.ImageIO;
public class Base64ToImage {
public static void main(String[] args) throws IOException {
String base64String = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAACW0lEQVR4nLWTT0jTURzHv7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7MzO7Mz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