這是新項(xiàng)目中把統(tǒng)計(jì)圖表導(dǎo)出到文檔的小功能研乒,現(xiàn)在寫出來方便自己在往后遇到找到。
/**
* 解析base64,返回圖片所在路徑
* @param base64Info
* @return
*/
public String decodeBase64(String base64Info){
if(StringUtils.isEmpty(base64Info)){
return null;
}
BASE64Decoder decoder = new BASE64Decoder();
String[] arr = base64Info.split("base64,");
//我是把圖片放在D盤了
File filePath = new File("D:");
//因?yàn)閳D表的圖片后綴是png,所以后臺生成的圖片也是它了
String picPath = filePath+ "/"+ UUID.randomUUID().toString() +".png";
try {
byte[] buffer = decoder.decodeBuffer(arr[1]);
OutputStream os = new FileOutputStream(picPath);
os.write(buffer);
os.flush();
os.close();
} catch (IOException e) {
throw new RuntimeException();
}
return picPath;
}