Please i'm suffering from one problem with JEE. Problem that I want to read two Images located in C:\tmp\ folder . I used below method for this :
// array of supported extensions (use a List if you prefer)
static final String[] EXTENSIONS = new String[]{
"gif", "png", "jpeg", "jpg","bmp" // and other formats you need
};
// File representing the folder that you select using a FileChooser
File dir = new File("C:\\tmp\\");
final File[] fs = dir.listFiles(IMAGE_FILTER);
ArrayList<Image> images = new ArrayList<Image>(100);
// filter to identify images based on their extensions
static final FilenameFilter IMAGE_FILTER = new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
for (final String ext : EXTENSIONS) {
if (name.endsWith("." + ext)) {
return (true);
}
}
return (false);
}
};
public Image image() {
BufferedImage img = null;
if (dir.isDirectory()) { // make sure it's a directory
for (final File f : dir.listFiles(IMAGE_FILTER)) {
try {
img = ImageIO.read(f);
// you probably want something more involved here
// to display in your UI
/* System.out.println("image: " + f.getName());
System.out.println(" width : " + img.getWidth());
System.out.println(" height: " + img.getHeight());
System.out.println(" size : " + f.length());*/
images.add(img);
} catch (final IOException e) {
// handle errors here
}
}
}
return img;
}
///////////////
then in jsf file i put code like this :
<ui:repeat value="#{imagesBean.images}" var="s" >
<h:graphicImage value="s" />
</ui:repeat>
As a result I got the icon of the image instead of the image.. Could you please support.. ty