pls my eclipse galileo int r = GImage.getRed(pixel);
int g = GImage.getGreen(pixel);
int b = GImage.getBlue(pixel);

also
int [][] array = image.getPixelArray();

as an error like its not in the library...

anyone pls

This is not enough informtion for anyone to be able to help you. Please post the code where the error happens (in code tags) and the exact complete error message.

import acm.graphics.*;
import acm.program.*;

public class BlacknWhite extends GraphicsProgram {
    public void run(){
        GImage image = new GImage ("akinfemi.jpg");
        GImage grayImage = createGrayScaleImage(image);

        add(image, 10, 50);
        add(grayImage, 100, 50);
    }
    private GImage createGrayScaleImage(GImage image){
        int [][] array = image.getPixelArray();

        int height = array.length;
        int width = array[0].length;

        for (int i = 0; i < height; i++){
            for (int j = 0; j < width; j++ ){
                int pixel = array[i][j];

                int r = GImage.getRed(pixel);
                int g = GImage.getGreen(pixel);
                int b = GImage.getBlue(pixel);

                int xx = computeLuminosity(r, g, b);

                array[i][j] = GImage.createdRGBPixel(xx, xx, xx);
            }


        }
    return GImage(array);
    }
    private int computeLuminosity(int r, int g, int b){
        return Math.round(0.299*r + 0.587*g + 0.114*b );
    }
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

getPixelArray, getRed, getGreen, getBlue are all underlined as wrong codes

This article has been dead for over six months. Start a new discussion instead.