【发布时间】:2011-07-11 18:03:30
【问题描述】:
我有一个字节数组图像。
我需要在 jsp 页面中以 jpg 格式显示该图像,并且在单击图像时,我可以将图像下载到我的电脑:
我正在从我的 mysql 数据库中加载图像作为字节数组..
我的代码是
ResultSet res = statement.executeQuery("SELECT * FROM
upload_data where user_id = "+userID);
while (res.next()) {
contactDetails = new ContactDetails();
contactDetails.setContactPhoto(res.getBytes("photo"));
byteArrayBackToImage1(res.getBytes("photo"));
contactsList.add(contactDetails);
}
public void byteArrayBackToImage1(byte[] imageInByte){
try{
Random rand = new Random();
int numNoRange = rand.nextInt();
String number = String.valueOf(numNoRange);
//convert byte array back to BufferedImage
InputStream in = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = ImageIO.read(in);
System.out.println("bImageFromConvert : "+bImageFromConvert);
/*ImageIO.write(bImageFromConvert, "jpg",
new File("c:\\"+number+".jpg")); */
}catch (Exception e) {
// TODO: handle exception
}
我需要在jsp中显示图片为
例如:image.jpg image2.jpg
通过点击 image.jsp ,我可以下载该图像并将其保存到我的电脑中
请帮忙
【问题讨论】:
-
响应我有一个db中对应特定id的图片列表,你需要唯一标识图片。
-
@jigar @BalusC 如果您可以在stackoverflow.com/questions/11124540/… 上提供一些输入,那将是一个很大的帮助。提前致谢。