81,122
社区成员




System.out.println("前面:"+imgStr); // 前后确认下 有些图可能不是 jpg,
imgStr=imgStr.replaceFirst("data:image/jpeg;base64,", "");
System.out.println("后来:"+imgStr);
// 这个操作没有必要
for(int i=0;i<b.length;++i)
{
if(b[i]<0)
{//调整异常数据
b[i]+=256;
}
}
public static boolean generateImage(String base64Code, String path) {
if (null == base64Code) {
return false;
}
byte[] base64Byte = Base64.decodeBase64(base64Code);
try {
OutputStream out = new FileOutputStream(path);
out.write(base64Byte);
out.flush();
out.close();
return true;
} catch (Exception e) {
return false;
}
}
其中Base64 是导入的这个包org.apache.commons.codec.binary.Base64
注意:也得吧前缀data:image/jpeg;base64,去掉