如何使用bufferedimage在jsp中打印图像

时间:2013-06-15 05:45:48

标签: jsp

我在app_be.getBytes()中有图像字节数组。

BufferedImage img = ImageIO.read(new ByteArrayInputStream(app_be.getBytes()));

我在我的jsp中有这一行。我在img.how中获得了图像可以在我的jsp img标签中显示这个图像可以帮助我。 除此图像外所有工作正常。 像这样我想打印img你可以帮帮我

<img src="<%= img%>" height="100%" width="100%" >

我试过这样<img src="<%= img.getSource()%>" height="100%" width="100%" > 但是也没有用,我不知道如何显示img plz帮助我。

1 个答案:

答案 0 :(得分:0)

在servlet中尝试此代码

BufferedImage image=ImageIO.read(new File("filepath");
ByteArrayOutputStream byteArrayOS=new ByteArrayOutputStream();
ImageIO.write(image, "jpg", byteArrayOS);
byte [] byteArray=byteArrayOS.toByteArray();
photo="data:image/jpg;base64,"+Base64.encode(byteArray);

将jsp中的照片值打印为

<img height="100px" src="${photo}" alt="Photo" />

这对我有用。瞥一眼这个