cicaprojekt/cicaprojekt/ImageStorage.java

32 lines
825 B
Java

package cicaprojekt;
import javax.imageio.ImageIO;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class ImageStorage {
private Map<String, BufferedImage> images;
public ImageStorage() throws IOException {
images = new HashMap<>();
File dir = new File(System.getProperty("user.dir"));
FileNameExtensionFilter filter = new FileNameExtensionFilter("N/A", "png");
for (File f : dir.listFiles()) {
if (filter.accept(f) && f.isFile()){
images.put(f.getName(), ImageIO.read(f));
}
}
}
public BufferedImage getImage(String filename) {
return images.get(filename);
}
}