每日总结12.6
百度图像增强与特效SDK实验
今天在完成实验的过程中遇到了一个问题,通过调用接口生成的图片格式为base64格式
需要转化为图片格式,下面为转码的部分类:
package com.baidu.test;
import java.io.*;
import java.util.Base64;
public class ImageUtils {
public static boolean generateImage(String imgData, String imgFilePath) throws IOException {
if (imgData == null) // 图像数据为空
return false;
Base64.Decoder decoder = Base64.getDecoder();
OutputStream out = null;
try {
out = new FileOutputStream(imgFilePath);
// Base64解码
byte[] b = decoder.decode(imgData);
out.write(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.flush();
out.close();
}
}
return true;
}
}

浙公网安备 33010602011771号