/** * 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; import java.io.File; // 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 Lect1028a { public static void main (String[] args) { System.out.println("Begin Java Exection"); System.out.println(""); // Select two pictures String filename; filename = FileChooser.pickAFile(); System.out.println (filename); int pos = filename.lastIndexOf(File.separatorChar); String s2 = filename.substring (0, pos); System.out.println (s2); FileChooser.setMediaPath(s2); System.out.println (FileChooser.getMediaDirectory()); Picture pict1 = new Picture(FileChooser.getMediaDirectory() + File.separator + "jenny-red.jpg"); System.out.println (pict1); // copy the pixels from pict1 into anotherPicture pict1 = reduceRedEye (pict1, 121, 95, 134, 106); pict1 = reduceRedEye (pict1, 175, 91, 187, 104); // display the picture pict1.explore(); // 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 reduceRedEye (Picture p1, int startX, int startY, int endX, int endY) { int width = p1.getWidth(); int height = p1.getHeight(); Color targetColor = new Color(179, 24, 42); // error check the X and Y parameter values if (startX < 0) { SimpleOutput.showError ("reduceRedEye: startX value less than zero"); return p1; } if (startY < 0) { SimpleOutput.showError ("reduceRedEye: startY value less than zero"); return p1; } if (endX > width) { SimpleOutput.showError ("reduceRedEye: endX value greater than width of picture"); return p1; } if (endY > height) { SimpleOutput.showError ("reduceRedEye: endY value greater than height of picture"); return p1; } for (int xPos = startX ; xPos < endX ; ++xPos ) { for (int yPos = startY ; yPos < endY ; ++yPos ) { Pixel pix = p1.getPixel (xPos, yPos); if (pix.colorDistance(targetColor) < 65) pix.setColor(Color.black); } } return p1; } } // end of Lect914b class