/** * 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 Lect1020b { 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 (height, width); // Set up a loop to access all the X position int xPos; int yPos; int xNew; int yNew; Pixel pix; Pixel pix2; int red; int green; int blue; for ( xPos = 0 ; xPos < width ; ++xPos ) { for ( yPos = 0 ; yPos < height ; ++yPos ) { // access the pixel to be modifed pix = p.getPixel (xPos, yPos); xNew = (height-1) - yPos; yNew = xPos; pix2 = resultPicture.getPixel (xNew, yNew); // get the colr values from the original pixel red = pix.getRed(); green = pix.getGreen(); blue = pix.getBlue(); // set those color values into the result pixel pix2.setRed(red); pix2.setGreen(green); pix2.setBlue(blue); } } return resultPicture; } // end of modifyPicture } // end of class