p:graphicImage具有StreamedContent抛出“流动态资源中的错误”

问题描述 投票:0回答:1

我有一个返回图像字节数组的方法。问题是当我尝试使用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>

任何想法如何解决它或为什么我收到此错误?

jsf primefaces graphicimage
1个回答
0
投票

我相信您缺少指示图像格式的“ data:image / jpg; base64”部分,

我会尝试以下操作:

<p:graphicImage url="data:image/jpg;base64,#{imageBean.imageContent}"></p:graphicImage>

[如果不提供您提供的作为源的显式格式,引擎将很可能以相对路径而不是编码的base64处理它。

© www.soinside.com 2019 - 2024. All rights reserved.