/** * Create a mirrored image. * * Items on the left hand side will appear on the right hand side * and vice-versa * * @author Pat Troy: troy AT uic DOT edu */ import java.util.*; import java.awt.*; public class Lect226h { public static void main(String[] args) { // create the picture and a turtle String fileName = FileChooser.pickAFile(); Picture pict = new Picture (fileName); // get an array of pixels Pixel pixArray[]; pixArray = pict.getPixels(); Picture pictNew = new Picture (pict.getWidth(), pict.getHeight()); System.out.println ("Width: " + pict.getWidth()); System.out.println ("Height: " + pict.getHeight()); System.out.println ("Total Pixels: " + pict.getWidth() * pict.getHeight()); System.out.println ("Array Length: " + pixArray.length ); System.out.println ( pixArray [0] ); System.out.println ("X: " + pixArray[0].getX()); System.out.println ("Y: " + pixArray[0].getY()); int index; Pixel pix, pixNew; int xPos, yPos; int red, green, blue; int red2, green2, blue2; int grayScaleAmount; for ( index = 0 ; index < pixArray.length ; index++ ) { // Access the pixel from the orignal image pix = pixArray[index]; // Access the correct pixel from the new Image xPos = pix.getX(); yPos = pix.getY(); pixNew = pictNew.getPixel (pict.getWidth() - xPos - 1, yPos); // access the 3 color intensities red = pix.getRed(); green = pix.getGreen(); blue = pix.getBlue(); // set the new color intensities pixNew.setRed(red); pixNew.setGreen(green); pixNew.setBlue(blue); // return the pixel to the pixel array pixArray[index] = pix; } // display the picture pictNew.show(); System.out.println ( pixArray [0] ); // save the picture to the computer // Note: Be sure to add the .jpg to the end of the filename!!!!! //fileName = FileChooser.pickAFile(); //System.out.println(fileName); //pict.write (fileName); } }