Java program – Converting color to grayscale

by Nideesh C on April 29, 2011 · 0 comments

in Java Programming




import java.awt.Color;

public class Grayscale {

    public static void main(String[] args) {
        Picture pic = new Picture(args[0]);
        int width  = pic.width();
        int height = pic.height();

        // convert to grayscale
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                Color color = pic.get(x, y);
                Color gray = Luminance.toGray(color);
                pic.set(x, y, gray);
            }
        }
        pic.show();
    }

}


/*************************************************************************
 *  Execution:    java Grayscale filename
 *
 *  Reads in an image from a file, converts it to grayscale, and
 *  displays it on the screen.
 *
 *  % java Grayscale image.jpg
 *
 *************************************************************************/



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Java program – Luminance library
  2. Java program – Converting to binary
  3. Java program – Albers squares
  4. Java program – Visualization client
  5. Java program – Casting to get a random integer

Leave a Comment

Previous post:

Next post: