added ImageStorage to precache images to remove IO bottleneck

This commit is contained in:
Kjistóf 2016-05-14 20:46:55 +02:00
parent 8c40c924d3
commit a7a530a9aa

View File

@ -0,0 +1,31 @@
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);
}
}