public Object setImgeToByteArray(HttpServletRequest request, HttpServletResponse response,
@PathVariable("imageName") String imageName){
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("image/jpeg");
//imgeUrl 拼接图片绝对路径
String imgeUrl =ParamsBean.MANAGER_URL+"/upload/"+
imageName.substring(0,4)+"/"+imageName.substring(4,6)+"/"+
imageName+".jpg";
java.net.URL url;
java.net.URLConnection conn;
java.io.InputStream is;
ServletOutputStream out = null;
try {
url = new java.net.URL(imgeUrl);
conn = url.openConnection();
is = conn.getInputStream();
BufferedImage bu= ImageIO.read(is);
out = response.getOutputStream();
//把这个jpg图像写到这个流中去
ImageIO.write(bu, "jpg",out);
} catch (IOException e) {
log.debug("setImgeToByteArray==>"+e);
}finally {
try {
out.flush();
} catch (IOException e) {
log.error("图片转换成输出流失败", e);
} finally {
try {
out.close();
} catch (IOException e) {
log.error("图片流关闭失败", e);
}
}
}
return null;
本文来源:https://www.wddqw.com/doc/0eb4afcd08a1284ac8504368.html
正在阅读:
以流的形式访问远程图片01-01
《教育参考》征稿启事01-01
我眼中的他作文800字-初三作文01-01
描写风的作文600字01-01
争与不争辩论稿个人方面01-01
24朵白玫瑰花代表什么意思01-01
会客有美堂,周邠长官与数僧同泛湖往北山,01-01
开立户清单01-01