我有一个返回图像字节数组的方法。问题是当我尝试使用StreamedContent在屏幕上显示它时,我得到流动态资源中的错误。
imageBean:
BufferedImage bImage = ImageIO.read(new File("imagepath"));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(bImage, "png", bos );
byte [] image = bos.toByteArray();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(image);
imageContent = new DefaultStreamedContent(byteArrayInputStream, "image/png");
xhtml:
<p:graphicImage value="#{imageBean.imageContent}"></p:graphicImage>
任何想法如何解决它或为什么我收到此错误?
我相信您缺少指示图像格式的“ data:image / jpg; base64”部分,
我会尝试以下操作:
<p:graphicImage url="data:image/jpg;base64,#{imageBean.imageContent}"></p:graphicImage>
[如果不提供您提供的作为源的显式格式,引擎将很可能以相对路径而不是编码的base64处理它。