// 输入图片base64字符串
public static byte[] base64StringToImage(String base64String) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
BASE64Decoder decoder = new sun.misc.BASE64Decoder();
byte[] bytes1 = decoder.decodeBuffer(base64String);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);
BufferedImage bi1 = ImageIO.read(bais);
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
//输出格式可变
ImageIO.write(bi1, "GIF", ios);
} catch (IOException e) {
e.printStackTrace();
}
// 返回byte[]数组
return baos.toByteArray();
}
图像类型转换:GIF->JPG、GIF->PNG、PNG->JPG、PNG->GIF、BMP->PNG
最新推荐文章于 2024-08-30 18:40:43 发布