3

I have a buffered image and I need to display it in a JSF page. Is there any UI component available which can display a buffered image directly? I am using JSF 2.2.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
salah atwa
  • 86
  • 11
  • Possible duplicate of [Show image as byte\[\] from database as graphic image in JSF page](https://stackoverflow.com/questions/30606503/show-image-as-byte-from-database-as-graphic-image-in-jsf-page) – Kukeltje Nov 16 '17 at 16:53

1 Answers1

3

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

Esteban Rincon
  • 2,040
  • 3
  • 27
  • 44