I want to display a dynamic photo with I'm storing the content of the image as a blob in the database , the content type in the photo entity is a byte array (byte[]) . I tried two diffrent ways but both was useless.
1)
public StreamedContent getImage() throws IOException {
byte[] img=photo.getContent();
InputStream in = new ByteArrayInputStream(img);
StreamedContent image = new DefaultStreamedContent(in,"image/jpeg");
return image;
}
2)
public StreamedContent getImage() throws IOException {
byte[] img=photo.getContent();
InputStream in = new ByteArrayInputStream(img);
BufferedImage bufferedImg = ImageIO.read(in);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImg, "jpeg", os);
StreamedContent image = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()),"image/jpeg");
return image;
}
and in the view page :
<p:graphicImage value="#{controller.image}"/>
So could someone help me to make it work !!