/** * Simple Picture manipulation * * @author Pat Troy: troy AT uic DOT edu */ 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 Lect1027d { 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 = width2; int height3 = width2; // 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; int yStart; int yEnd; int temp; Pixel pix1; Pixel pix2; Pixel pix3; Pixel fromPix; Pixel toPix; int red; int green; int blue; Color c1 = new Color (18, 155, 51); for ( xPos = 0 ; xPos < width2 ; ++xPos ) { for ( yPos = 0 ; yPos < height2 ; ++yPos ) { if ( xPos >= width1 || yPos >= height1 ) { fromPix = p2.getPixel (xPos, yPos); } else { // access the pixel to be modifed pix1 = p1.getPixel (xPos, yPos); if ( Pixel.colorDistance (c1, pix1.getColor()) < 10) { fromPix = p2.getPixel (xPos, yPos); } else { fromPix = p1.getPixel (xPos, yPos); } } toPix = resultPicture.getPixel (xPos, yPos); // get the colr values from the original pixel red = fromPix.getRed(); green = fromPix.getGreen(); blue = fromPix.getBlue(); // set those color values into the result pixel toPix.setRed(red); toPix.setGreen(green); toPix.setBlue(blue); } } return resultPicture; } // end of modifyPicture } // end of class