Primefaces 6.1 png图像显示,黑色背景

时间:2017-10-04 05:54:30

标签: primefaces jsf-2 background png transparent

我在PrimeFaces 6.1中难以显示png图像。

图像是以字节数组格式从数据库加载的。 jpg显示效果很好但是png始终显示为黑色背景。

这是我的jsf代码片段:

<p:graphicImage value="#{fileControlBean.image}">
   <f:param name="fileId" value="#{file.fileId}" />
</p:graphicImage>

和back bean as:

public StreamedContent getImage() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();

    if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
        // So, we're rendering the HTML. Return a stub StreamedContent so that it will generate right URL.
        return new DefaultStreamedContent();
    }
    else {
        // So, browser is requesting the image. Return a real StreamedContent with the image bytes.
        String fileId = context.getExternalContext().getRequestParameterMap().get("fileId");
        File file = (File) fileBean.getFileCache().get(fileId);
        return new ByteArrayContent(file.getThumbnail(),file.getFileType(),file.getFileName());
    }
}

所有其他jpg显示正常,但png图像看起来透明设置为1.我的问题:如何将其设置回透明?或者这是一个错误?

1 个答案:

答案 0 :(得分:0)

抱歉,这个任务没有被正确询问。黑色背景问题是由png self引起的,因为它带有透明度问题。我用inkscape再次重新生成了png。黑色的背景消失了。