public static boolean GenerateImage(String imgStr, String imgFilePath) {
byte[] bytes = null;
try {
BASE64Decoder decoder = new BASE64Decoder();
int j = imgStr.indexOf(',');
if (j != -1) {
imgStr = imgStr.substring(j + 1);
}
bytes = decoder.decodeBuffer(imgStr);
for (int i = 0; i < bytes.length; ++i) {
if (bytes[i] < 0) {
bytes[i] += 256;
}
}
File file = new File(imgFilePath);
if (!file.exists()) {
file.createNewFile();
}
OutputStream out = new FileOutputStream(file);
out.write(bytes);
out.flush();
out.close();
return true;
} catch (Exception e) {
return false;
}
}
base64码生成图片
最新推荐文章于 2024-08-11 12:00:00 发布