//将前台传的base64格式图片保存到本地
public void picture(HttpServletRequest request){
request.setCharacterEncoding("utf-8");
String imgStr = request.getParameter("param");
String path = "D:\\a"+System.currentTimeMillis()+".JPEG";
byte[] bs = new BASE64Decoder().decodeBuffer(imgStr);
for(int i=0;i<bs.length;i++){
if (bs[i]<0){
bs[i] += 256;}
}
OutputStream out = new FileOutputStream(path);
out.write(bs);
out.flush();
out.close();
}
将图片转换成BASE64格式
InputStream in = null;
byte[] data = null;
in = new FileInputStream("C://Users/1/Desktop/a.PNG");
data = new byte[in.available];
in.read(data);
in.close;
BASE64Encoder encoder = new BASE64Encoder();
String imgStr = encoder.encode(data);