import java.awt.*; import java.awt.image.*; import javax.swing.*; public class OldPicture { public String filename; public ImageIcon img; public int [] pixels; private int w; private int h; public void setFilename( String f) { filename = f; loadImage(); } public String getFileName() { return filename; } public void loadImage() { img = new ImageIcon(filename); // define the rectange of pixels you want to grab (whole image). int x = 0; // start x int y = 0; // start y w = img.getIconWidth(); // width h = img.getIconHeight(); // height // buffer to hold the pixels you grab pixels = new int[w*h]; // a Pixel Grabber to work on your image. This tells 'pg' which pixels to // grab when asked. PixelGrabber pg = new PixelGrabber(img.getImage(), // your image x, y, // origin of rect to grab w, h, // width/height of rect to grab pixels, // buffer to store pixels 0, // offset into 'pixels' w // dist between rows in 'pixels' ); // grab the pixels now! try { pg.grabPixels(); } catch (InterruptedException e) { System.err.println("interrupted waiting for pixels!"); return; } } public int getWidth() { return w; } public int getHeight() { return h; } public int getBasicPixel(int x, int y) { // to access pixel at row 'j' and column 'i' from the upper-left corner of // image. return pixels[y * w + x]; } public Pixel getPixel(int x, int y) { return new Pixel(this,x,y); } public static void main( String args[] ) { Picture p = new Picture(); p.setFilename("/Users/guzroot/Documents/barbara.jpg"); System.out.println("Width is "+p.getWidth()); System.out.println("Height is "+p.getHeight()); Pixel px = p.getPixel(10,10); System.out.println("Alpha at 10,10 is "+px.getAlpha()); System.out.println("Red is "+px.getRed()); System.out.println("Green is "+px.getGreen()); System.out.println("Blue is "+px.getBlue()); } }