日期:2014-05-16 浏览次数:20303 次
1.OutputStream write BufferedInputStream bis = new BufferedInputStream(blob.getBinaryStream());? BufferedInputStream inputimage =?new?BufferedInputStream(blob.getBinaryStream());??? BufferedImage image = null;??? 3.jsp <img?src="image.do"></img>?? 注:要注意思可能会有缓存问题。
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());?
InputStream in = blob.getBinaryStream();?
int size = 0;?
int b = 0;?
byte[] buffer = new byte[8192];?
response.setContentType("image/jpeg");?
response.setContentLength(in.available());?
while((b=bis.read()) != -1) {?
bos.write(b);?
}?
bos.flush();?
bos.close();?
bis.close();
2.ImageIO.write
try?
{???
?? image = ImageIO.read(inputimage);???
?? ServletOutputStream sos = response.getOutputStream();???
?? ImageIO.write(image, "jpg", sos);???
?? JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);???
?? encoder.encode(image);???
?? inputimage.close();???
?? sos.flush();???
}???
catch(Exception e)???
{???
?? System.out.println(e);???
}??