直接上代码:
/**
* Base64转换为图片服务
* targetPath 输出视频文件路径,不需要文件名
* */
public static void base64ToImg(String base64,String targetPath){
File file = null;
FileOutputStream fops = null;
base64 = base64.replace("data:image/jpeg;base64,","");
byte[] buff = DatatypeConverter.parseBase64Binary(base64);
try {
fops = new FileOutputStream(new File(targetPath));
fops.write(buff);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("--------------------------------"+"图片转换完成"+"--------------------------------");
}