/** * Class for creating a template for a simple Java program * * @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. public class Lect225g { public static void main (String[] args) { String fname = FileChooser.pickAFile(); //System.out.println (fname); Picture pict = new Picture (fname); // call method makeGrayScale(pict); pict.explore(); } public static void makeGrayScale (Picture pict) { // store the pixels in an array Pixel[] pixelArray; pixelArray = pict.getPixels (); //System.out.println ("pixelArray lenght: " + pixelArray.length ); // modify each pixel in the picture int count; for (count = 0 ; count < pixelArray.length; count++) { // Color c = pixelArray[count].getColor(); int redAmount, greenAmount, blueAmount, grayAmount; Pixel p; p = pixelArray[count]; redAmount = p.getRed(); greenAmount = p.getGreen(); blueAmount = p.getBlue (); //redAmount = 255 - redAmount; //greenAmount = 255 - greenAmount; //blueAmount = 255 - blueAmount; grayAmount = (int)((redAmount*0.299) + (greenAmount*0.587) + (blueAmount*0.114)); p.setRed (grayAmount); p.setGreen (grayAmount); p.setBlue (grayAmount); } } } // end of class