[英]Image Display Using p:graphicImage. Pictures appear like negatives
I am using Primefaces p:graphicImage to display the image of every logged in users. 我正在使用Primefaces p:graphicImage显示每个已登录用户的图像。 Everything is working near fine except that my photos appear like negatives.
除了我的照片看起来像底片之外,其他所有东西都运行良好。 What could I be doing wrong.
我可能做错了什么。 Here is my code :
这是我的代码:
<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());
}
}
What is it I could be doing wrong. 我可能做错了什么。 The same pictures displayed in a normal swing application display without any problem
正常摇摆应用程序中显示的相同图片没有任何问题
Update On Code 更新代码
@BalusC Here is the quick test code that displays the image on swing. @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;
........
Could it be that the Toolkit.getDefaultToolkit().createImage(image); 可能是Toolkit.getDefaultToolkit()。createImage(image); line is doing the re-invert.
线正在做重新反转。 The images were populated using a different application and this is more of an update to have it as a web-based application.
图像是使用其他应用程序填充的,这更多的是将其作为基于Web的应用程序的更新。
Thanks for your advice in advance. 谢谢您的建议。
JSF/PrimeFaces is just the presenter and doesn't invert the images at all. JSF / PrimeFaces只是演示者,根本不会反转图像。 Otherwise anyone else in the world using JSF/PrimeFaces would have faced the same problem.
否则,使用JSF / PrimeFaces的世界上任何其他人都将面临相同的问题。 Your problem lies deeper.
您的问题更深了。 It's more likely that the images are already stored as negatives in DB and that your existing Swing/Java2D code is written in such way that it re-inverts the images before displaying, perhaps during a badly written resizing/cropping process.
更有可能的是,图像已经作为底片存储在DB中,并且您现有的Swing / Java2D代码以这样的方式编写:在显示之前,可能是在编写错误的调整大小/裁剪过程中,将图像重新反转。
So, to fix the problem, refocus on the code responsible for storing those images in the DB (and don't forget to fix the Swing/Java2D code to not re-invert those anymore). 因此,要解决此问题,请重新关注负责将这些图像存储在数据库中的代码(并且不要忘记修复Swing / Java2D代码以不再重新反转这些图像)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.