How to display buffered image in JSF without writing image on disk?

巧了我就是萌 提交于 2019-12-01 09:32:01

If you only have the buffered image, you could use the Omnifaces library to which allows you to render images by passing a byte[] to the component

<o:graphicImage value="#{bean.image}" dataURI="true" />

If you have the buffered image you could convert to byte array like so:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write([image],[image_extension], baos);
byte[] imageToPassAsValueAttr = baos.toByteArray();

You could also create a servlet to receive the image id as a get request and from that point on you can get the parameter value, find the resource and write the image content to response.

@BalusC has a nice example here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!