簡體   English   中英

使用p:graphicImage顯示圖像。 圖片看起來像底片

[英]Image Display Using p:graphicImage. Pictures appear like negatives

我正在使用Primefaces p:graphicImage顯示每個已登錄用戶的圖像。 除了我的照片看起來像底片之外,其他所有東西都運行良好。 我可能做錯了什么。 這是我的代碼:

<sec:authorize access="isAuthenticated()">
   <span>
     <p:graphicImage value="#{currentUser.image}" class="img-thumbnail pull-right"
        height="80px;" width="80px;" >
       <f:param name="id" value="#{request.remoteUser}" />
     </p:graphicImage>
   </span>

.....

And here is the JSF Managed Bean


@Named(value = "currentUser")
@ApplicationScoped
public class CurrentUser implements Serializable {

    @EJB
    private VempDetailsFacade vempDetailsFacade;
    private VempDetails details;

    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 imageId = context.getExternalContext().getRequestParameterMap().get("id");
            details = vempDetailsFacade.find(imageId);
            if (details != null) {
                try {
                    return new DefaultStreamedContent(new ByteArrayInputStream(details.getEmpImage()));
                } catch (Exception e) {
                    System.err.println("No Image Retrieved : "+e.getMessage());
                }
            }
            return null;

        }
    }

    public VempDetails getDetails() {
        return details;
    }

    public void setDetails(VempDetails details) {
        this.details = details;
    }

    @PostConstruct
    public void init() {
        details = vempDetailsFacade.
                find(FacesContext.getCurrentInstance().getExternalContext().getRemoteUser());
    }

}

我可能做錯了什么。 正常搖擺應用程序中顯示的相同圖片沒有任何問題

更新代碼

@BalusC這是快速顯示擺動圖像的測試代碼。

public DisplayImage() {
        super("Image Display");
        setSize(600, 600);
        connection = getConnection();
        try { 
            statement = connection
                    .prepareStatement("SELECT empImage FROM v_empDetails WHERE empCode=?");
            statement.setString(1, "009");
            result = statement.executeQuery();

            byte[] image = null;
            //just a result anyway
            while (result.next()) {
                image = result.getBytes(1);         
            }
            Image img = Toolkit.getDefaultToolkit().createImage(image);
            ImageIcon icon = new ImageIcon(img);
            JLabel lPhoto = new JLabel();
            lPhoto.setIcon(icon);
            add(lPhoto);

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        setVisible(true);
    }

    public Connection getConnection() {
        Connection connection = null;
........

可能是Toolkit.getDefaultToolkit()。createImage(image); 線正在做重新反轉。 圖像是使用其他應用程序填充的,這更多的是將其作為基於Web的應用程序的更新。

謝謝您的建議。

JSF / PrimeFaces只是演示者,根本不會反轉圖像。 否則,使用JSF / PrimeFaces的世界上任何其他人都將面臨相同的問題。 您的問題更深了。 更有可能的是,圖像已經作為底片存儲在DB中,並且您現有的Swing / Java2D代碼以這樣的方式編寫:在顯示之前,可能是在編寫錯誤的調整大小/裁剪過程中,將圖像重新反轉。

因此,要解決此問題,請重新關注負責將這些圖像存儲在數據庫中的代碼(並且不要忘記修復Swing / Java2D代碼以不再重新反轉這些圖像)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM