/** * 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 Lect1025a { public static void main (String[] args) { // Access and open the first picture String filename = FileChooser.pickAFile (); Picture p = new Picture (filename); // Access and open the second picture String filename2 = FileChooser.pickAFile (); Picture p2 = new Picture (filename2); // call the method to modify the Pictture Picture p3; p3 = modifyPicture (p, p2); // explore (display) the picture p3.explore(); // get a new filename and save the picture //String saveFilename = FileChooser.pickAFile (); //p2.write (saveFilename); } // end of main public static Picture modifyPicture (Picture p1, Picture p2) { // get the width and height of the picture int width1 = p1.getWidth(); int height1 = p1.getHeight(); System.out.println ("Width: " + width1 + ", Height: " + height1); // get the width and height of the picture int width2 = p2.getWidth(); int height2 = p2.getHeight(); System.out.println ("Width: " + width2 + ", Height: " + height2); // determine the width and height of the result int width3 = width1 + width2; int height3; if ( height1 > height2 ) { height3 = height1; } else { height3 = height2; } // create the new Picture that will be returned Picture resultPicture; resultPicture = new Picture (width3, height3); // Set up a loop to access all the X position int xPos; int yPos; Pixel pix1; Pixel pix2; Pixel pix3; int red; int green; int blue; for ( xPos = 0 ; xPos < width1 ; ++xPos ) { for ( yPos = 0 ; yPos < height1 ; ++yPos ) { // access the pixel to be modifed pix1 = p1.getPixel (xPos, yPos); pix3 = resultPicture.getPixel (xPos, yPos); // get the colr values from the original pixel red = pix1.getRed(); green = pix1.getGreen(); blue = pix1.getBlue(); // set those color values into the result pixel pix3.setRed(red); pix3.setGreen(green); pix3.setBlue(blue); } } for ( xPos = 0 ; xPos < width2 ; ++xPos ) { for ( yPos = 0 ; yPos < height2 ; ++yPos ) { // access the pixel to be modifed pix2 = p2.getPixel (xPos, yPos); pix3 = resultPicture.getPixel (xPos + width1, yPos); // get the colr values from the original pixel red = pix2.getRed(); green = pix2.getGreen(); blue = pix2.getBlue(); // set those color values into the result pixel pix3.setRed(red); pix3.setGreen(green); pix3.setBlue(blue); } } return resultPicture; } // end of modifyPicture } // end of class