/** * Rotation of an image by 90 degrees clockwise * * @author Pat Troy: troy AT uic DOT edu */ import java.util.*; import java.awt.*; public class Lect1021b { 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(); 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] ); int index; Pixel pix, pix2; Color cl1, cl2; int red, green, blue, gray; int xPos, yPos, newX, newY; int originalWidth, originalHeight; originalWidth = pict.getWidth(); originalHeight = pict.getHeight(); // create the duplicate "canvas" Picture pict2 = new Picture (originalHeight, originalWidth); for ( index = 0 ; index < pixArray.length ; index++ ) { //get the pixel from the source image pix = pixArray[index]; // get the x, y coordinates for the source pixel xPos = pix.getX(); yPos = pix.getY(); // get the destination pixel using the x,y coordinates newX = originalHeight - 1 - yPos; // the "- 1" is to adjust of X value range newY = xPos; pix2 = pict2.getPixel (newX, newY); // retrieve the source color information red = pix.getRed(); green = pix.getGreen(); blue = pix.getBlue(); // store the color information in the destination pixel pix2.setRed (red); pix2.setGreen (green); pix2.setBlue (blue); } // display the picture pict.show(); pict2.show(); // 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); pict2.write (fileName); } }