【问题标题】:Primefaces 6.1 png image display with black backgroundPrimefaces 6.1 png图像显示黑色背景
【发布时间】:2018-03-15 10:27:22
【问题描述】:

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

图像是以字节数组格式从数据库加载的。 jpg 显示良好,但 png 总是以黑色背景显示。

这是我的 jsf 代码片段:

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

返回 bean 为:

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。我的问题:如何将其设置回透明?或者这是一个错误?

【问题讨论】:

    标签: primefaces jsf-2 background png transparent


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 2013-09-26
      • 2015-01-15
      • 1970-01-01
      • 2023-04-10
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多