/** * Construct the <code>BufferedImage</code> from the given file. The file can be given as an URL, * or a reference to local image file. If this image has been loaded already, use the saved * version. * * @param filename the file name for the desired image */ public ImageMaker(String filename) { /** now we set up the image file for the user to process */ try { this.inputfile = new File(filename); String abs = inputfile.getCanonicalPath(); if (loadedImages.containsKey(abs)) { this.image = loadedImages.get(abs); this.width = this.image.getWidth(); this.height = this.image.getHeight(); } else { this.imageSource = ImageIO.read(this.inputfile); this.width = this.imageSource.getWidth(); this.height = this.imageSource.getHeight(); this.cmodel = this.imageSource.getColorModel(); this.image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_ARGB); this.colorOp = new ColorConvertOp( this.cmodel.getColorSpace(), image.getColorModel().getColorSpace(), null); this.colorOp.filter(this.imageSource, this.image); loadedImages.put(abs, this.image); } } catch (IOException e) { System.out.println("Could not open the file"); } }