added ImageStorage to precache images to remove IO bottleneck
This commit is contained in:
		
							
								
								
									
										31
									
								
								cicaprojekt/ImageStorage.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								cicaprojekt/ImageStorage.java
									
									
									
									
									
										Normal 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); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user