/** * Loads a PPM image from a file. * * @param fileName Location of PPM image * @param storage (Optional) Storage for output image. Must be the width and height of the image being read. * Better performance of type BufferedImage.TYPE_INT_RGB. If null or width/height incorrect a new image * will be declared. * @return The read in image * @throws IOException */ public static BufferedImage loadPPM( String fileName , BufferedImage storage ) throws IOException { return loadPPM(new FileInputStream(fileName),storage); }
/** * A function that load the specified image. If anything goes wrong it returns a * null. */ public static BufferedImage loadImage(String fileName) { BufferedImage img; try { img = ImageIO.read(new File(fileName)); if( img == null) { if( fileName.endsWith("ppm") || fileName.endsWith("PPM") ) { return loadPPM(fileName,null); } else if( fileName.endsWith("pgm") || fileName.endsWith("PGM") ) { return loadPGM(fileName, null); } } } catch (IOException e) { return null; } return img; }