byte[] src = roiAbgr.getByteArray(0,w * h * 4);
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
如何用BufferedImage这个类把src 转为jpg图片
byte[] src = roiAbgr.getByteArray(0,w * h * 4);
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
如何用BufferedImage这个类把src 转为jpg图片
代码如下,望采纳
/**
* 获取验证码图片
* @return jpg
*/
@RequestMapping(value = "/getCodeImage")
public void getValidateCodeImage(HttpServletRequest request,HttpServletResponse response) throws IOException {
JSONObject json = new JSONObject();
PrintWriter out = null;
out = response.getWriter();
byte[] src = roiAbgr.getByteArray(0,w * h * 4);
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
//临时图片路径
File file = new File("d:\\image\\" + UUID.randomUUID().toString() + ".jpg");
if(!(file.getParentFile().exists())){ //判断d:\image目录是否存在
file.getParentFile().mkdir();
}
//输出到临时图像
ImageIO.write(image, "jpg", file);//jpg可以换成你想要的图片格式
this.file = file;
json.put("validateCodeImage", file);
if (null != out) {
out.close();
}
}