/**
* 将接收的字符串转换成图片保存
* @param imgStr base64格式的二进制流转换的字符串
* @param imgPath 图片的保存路径
* @param imgName 图片的名称
* @param imgType 图片类型
* @return
* 1:保存正常
* 0:保存失败
*/
public static int saveToImgByStr(String imgStr,String imgPath,String imgName,String imgType){
int stateInt = 1;
try{
BASE64Decoder decoder=new BASE64Decoder();
byte[] bytes=decoder.decodeBuffer(imgStr);
File file=new File(imgPath,imgName+"."+imgType);
FileOutputStream fos=new FileOutputStream(file);
fos.write(bytes);
fos.flush();
fos.close();
System.out.println("图片生成成功");
}catch(Exception e){
e.printStackTrace();
stateInt=0;
System.out.println("图片生成失败");
}
return stateInt;
}
图片 二进制 转换
最新推荐文章于 2023-03-10 17:15:46 发布