uploadPhoto(@RequestParam("upimage") MultipartFile imageFile,HttpServletRequest request,HttpServletResponse response) throws Exception {
Map
result = new HashMap();
boolean tag =false;
String unid = request.getParameter("unid");
String x = request.getParameter("x");
String y = request.getParameter("y");
String h = request.getParameter("h");
String w = request.getParameter("w");
// 页面实际图片宽高
String pheight = request.getParameter("ph");
String pweight = request.getParameter("pw");
// 切图参数
int imageX = Integer.parseInt(x);
int imageY = Integer.parseInt(y);
int imageH = Integer.parseInt(h);
int imageW = Integer.parseInt(w);
int srcH = Integer.parseInt(pheight);
int srcW = Integer.parseInt(pweight);
String realPath = request.getSession().getServletContext().getRealPath("/");
String resourcePath = "resources/uploadImages/";
try {
if (imageFile != null) {
if (FileUploadUtil.allowUpload(imageFile.getContentType())) {
// 这里开始截取操作
byte[] b = ImageCut.imgCut(imageFile.getInputStream(),imageX,imageY,imageW,imageH,srcW,srcH);
if (b != null) {
// 存入数据库
User user = userService.selectByPrimaryKey(unid);
user.setPhoto(b);
tag = (userService.updateByPrimaryKeySelective(user)==1)?tag=true:tag;
result.put("result",tag);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
result.put("result",tag);
return result;
}
= desWidth && srcHeight >= desHeight) {
Image image = bi.getScaledInstance(srcWidth,srcHeight,Image.SCALE_DEFAULT);
cropFilter = new CropImageFilter(x,y,desWidth,desHeight);
img = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(image.getSource(),cropFilter));
BufferedImage tag = new BufferedImage(desWidth,desHeight,BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(img,null);
g.dispose();
//
输出文件
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(tag,"JPEG",out);
return out.toByteArray();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}