我的程序应该通过存储在数据库中的 id 为用户显示头像(图像)。存储在磁盘上的图像。我使用 BufferedDynamicImageResource 显示图像,但问题是始终显示首先打开的图片。如何解决?
图片阅读:
public ResourceReference getImage() {
return new ResourceReference(UserPage.class, "image") {
private static final long serialVersionUID = 2127616487187967396L;
@Override
public IResource getResource() {
BufferedImage image = null;
File f = null;
//read image
try {
f = new File("PATH");
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
image = ImageIO.read(new FileImageInputStream(f));
System.out.println("Reading complete.");
} catch (IOException e) {
System.out.println("Error: " + e);
}
BufferedDynamicImageResource resource = new BufferedDynamicImageResource();
resource.setImage(image);
return resource;
}
};
}
函数调用:
form.add(new Image("userImg", getImage()));
我正在使用 Wicket 7.8.0