/** * Loads a PGM image from a file. * * @param fileName Location of PGM 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_BYTE_GRAY. If null or width/height incorrect a new image * will be declared. * @return The read in image * @throws IOException */ public static BufferedImage loadPGM( String fileName , BufferedImage storage ) throws IOException { return loadPGM(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; }