petite/src/wombat/scheme/libraries/ImageAPI.java
public static ImageData readImage(String dir, String filename) throws IOException {
		if (!new File(filename).isAbsolute())
			filename = new File(dir, filename).getCanonicalPath();
		
		if (!new File(filename).exists())
			throw new IllegalArgumentException("Error in read-image: '" + filename + "' does not exist");
		
		BufferedImage bi_orig = ImageIO.read(new File(filename));
		
		if (bi_orig == null) {
			String filetypes = "";
			for (String s : ImageIO.getReaderFileSuffixes())
				filetypes += s + " ";
			filetypes = filetypes.trim();
			
			throw new IllegalArgumentException("Error in read-image: Unable to read '" + filename + "'. Valid file types are: " + filetypes);
		}
			
		// This is a fix to deal with getRGB screwing up on previously grayscale images
		BufferedImage bi = new BufferedImage(bi_orig.getWidth(), bi_orig.getHeight(), BufferedImage.TYPE_INT_ARGB);
		bi.getGraphics().drawImage(bi_orig, 0, 0, null);
		
		int[] data = new int[bi.getWidth() * bi.getHeight()];
		bi.getRGB(0, 0, bi.getWidth(), bi.getHeight(), data, 0, bi.getWidth());
		
		return new ImageData(bi.getWidth(), bi.getHeight(), data);
	}
/**
	 * Read an image into a bytestream.
	 * @param dir The directory to read from.
	 * @param filename The file to read.
	 * @return A stream of encoded data. The first two values are rows then columns, then the sequence is [r,g,b,a] across rows then down.
	 * @throws IOException If we cannot read the image.
	 */
Read an image into a bytestream.
@param dir The directory to read from.
@param filename The file to read.
@return A stream of encoded data. The first two values are rows then columns, then the sequence is [r,g,b,a] across rows then down.
@throws IOException If we cannot read the image.
Read an image into a bytestream . @param dir The directory to read from . @param filename The file to read . @return A stream of encoded data . The first two values are rows then columns then the sequence is [ r g b a ] across rows then down . @throws IOException If we cannot read the image .
public static ImageData readImage(String dir, String filename) throws IOException {
		if (!new File(filename).isAbsolute())
			filename = new File(dir, filename).getCanonicalPath();
		if (!new File(filename).exists())
			throw new IllegalArgumentException("Error in read-image: '" + filename + "' does not exist");
		BufferedImage bi_orig = ImageIO.read(new File(filename));
		if (bi_orig == null) {
			String filetypes = "";
			for (String s : ImageIO.getReaderFileSuffixes())
				filetypes += s + " ";
			filetypes = filetypes.trim();
			throw new IllegalArgumentException("Error in read-image: Unable to read '" + filename + "'. Valid file types are: " + filetypes);
		}
		BufferedImage bi = new BufferedImage(bi_orig.getWidth(), bi_orig.getHeight(), BufferedImage.TYPE_INT_ARGB);
		bi.getGraphics().drawImage(bi_orig, 0, 0, null);
		int[] data = new int[bi.getWidth() * bi.getHeight()];
		bi.getRGB(0, 0, bi.getWidth(), bi.getHeight(), data, 0, bi.getWidth());
		return new ImageData(bi.getWidth(), bi.getHeight(), data);
	}
public static ImageData readImage ( String dir , String filename ) throws IOException { if ( ! new File ( filename ) . isAbsolute ( ) ) filename = new File ( dir , filename ) . getCanonicalPath ( ) ; if ( ! new File ( filename ) . exists ( ) ) throw new IllegalArgumentException ( "Error in read-image: '" + filename + "' does not exist" ) ; BufferedImage bi_orig = ImageIO . read ( new File ( filename ) ) ; if ( bi_orig == null ) { String filetypes = "" ; for ( String s : ImageIO . getReaderFileSuffixes ( ) ) filetypes += s + " " ; filetypes = filetypes . trim ( ) ; throw new IllegalArgumentException ( "Error in read-image: Unable to read '" + filename + "'. Valid file types are: " + filetypes ) ; } BufferedImage bi = new BufferedImage ( bi_orig . getWidth ( ) , bi_orig . getHeight ( ) , BufferedImage . TYPE_INT_ARGB ) ; bi . getGraphics ( ) . drawImage ( bi_orig , 0 , 0 , null ) ; int [ ] data = new int [ bi . getWidth ( ) * bi . getHeight ( ) ] ; bi . getRGB ( 0 , 0 , bi . getWidth ( ) , bi . getHeight ( ) , data , 0 , bi . getWidth ( ) ) ; return new ImageData ( bi . getWidth ( ) , bi . getHeight ( ) , data ) ; }
Read an image into a bytestream.
Read an image into a bytestream .
// This is a fix to deal with getRGB screwing up on previously grayscale images