/** * Simple Picture manipulation * * @author Pat Troy: troy AT uic DOT edu */ // Note the name of the class in the following line MUST // match the name of the file. This is stored in a file // named: Template.java public class Lect1101e { public static void main (String[] args) { // Access and open the picture String filename = FileChooser.pickAFile (); Picture p = new Picture (filename); // call the method to modify the Pictture Picture p2; p2 = modifyPicture (p); // explore (display) the picture p2.explore(); // get a new filename and save the picture //String saveFilename = FileChooser.pickAFile (); //p2.write (saveFilename); } // end of main public static Picture modifyPicture (Picture p) { // get the width and height of the picture int width = p.getWidth(); int height = p.getHeight(); System.out.println ("Width: " + width + ", Height: " + height); // create the new Picture that will be returned Picture resultPicture; resultPicture = new Picture (width , height); // Set up a loop to access all the X position int xPos; int yPos; int xOrig; int yOrig; int xNew; int yNew; Pixel pix1a; Pixel pix1b; Pixel pix1c; Pixel pix2; int red; int green; int blue; for ( xPos = 0 ; xPos < width -1 ; ++xPos ) { for ( yPos = 0 ; yPos < height - 1 ; ++yPos ) { // access the pixel to be modifed pix1a = p.getPixel (xPos, yPos); pix1b = p.getPixel (xPos + 1, yPos); pix1c = p.getPixel (xPos, yPos + 1); pix2 = resultPicture.getPixel (xPos, yPos); if ( (Pixel.colorDistance (pix1a.getColor(), pix1b.getColor()) < 25) && (Pixel.colorDistance (pix1a.getColor(), pix1c.getColor()) < 25) ) { // set those color values into the result pixel pix2.setRed(255); pix2.setGreen(255); pix2.setBlue(255); } else { // set those color values into the result pixel pix2.setRed(0); pix2.setGreen(0); pix2.setBlue(0); } } } return resultPicture; } // end of modifyPicture } // end of class