0

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[j];

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

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

array[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 );
}
}

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by kramerd
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.