/** * Class for creating a template for a simple Java program * * @author Pat Troy: troy AT uic DOT edu */ // import the library with the color information import java.awt.Color; // 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 Lect1019c { public static void main (String[] args) { System.out.println("Begin Java Exection"); System.out.println(""); // Select two pictures String filename = FileChooser.pickAFile(); System.out.println (filename); Picture pict1 = new Picture(filename); // call the method to modify the picture Picture anotherPicture; anotherPicture = modifyPicture (pict1); // display the picture anotherPicture.show(); // Save the picture //String fname; //fname = FileChooser.pickAFile(); //System.out.println ("File: " + filename); //pict1.write (fname); System.out.println(""); System.out.println("End Java Exection"); } // end of the method main public static Picture modifyPicture (Picture pictA) { // get the width and height of the picture int width = pictA.getWidth(); int height = pictA.getHeight(); //System.out.println ("Width: " + width); //System.out.println ("Height: " + height); // create a new Picture to store the grayScale image Picture pictC = new Picture (width, height); // set up a nested loop (one loop inside another) to access each pixel int xLoopCounter; int yLoopCounter; // the outer loop varies the X position (which column the pixel is in) for ( xLoopCounter = 0 ; xLoopCounter < width ; xLoopCounter++ ) { // the inner loop varies the Y position (which row the pixel is in) for ( yLoopCounter = 0 ; yLoopCounter < height ; yLoopCounter++ ) { // access a pixel and its colors from the first picture Pixel pA = pictA.getPixel (xLoopCounter, yLoopCounter); int red = pA.getRed(); int green = pA.getGreen(); int blue = pA.getBlue(); // calculate the new position for the pixel information int newXPos, newYPos; newXPos = width - xLoopCounter - 1; newYPos = height - yLoopCounter - 1; // save the modified color values Pixel pC = pictC.getPixel (newXPos, newYPos); pC.setRed(red); pC.setGreen(green); pC.setBlue(blue); } } // add the code to return the newly created picture return pictC; } // end of the method to modify the picture } // end of Lect914b class