I'm stored the content of the image as a blob in the database , the content type in the photo entity is a byte array (byte[]) で動的な写真を表示したい。私は2つの異なる方法を試しましたが、どちらも役に立たなかった.
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;
}
およびビューページで:
<p:graphicImage value="#{controller.image}"/>
だから、誰かがそれを機能させるのを手伝ってくれませんか!!