[英]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.