I am trying to manipulate an image to be black and white, and have tried many different codes, but can't figure it out. Can anyone help me please?


1 2 3 4 | GreenfootImage image=getImage(); image.setColor(Color.WHITE); image.fill(); setImage(image); |
1 | import java.awt.Color; |
1 2 3 4 5 6 7 8 9 10 11 | GreenfootImage getBlackWhiteImage(String Image){ GreenfootImage i = new GreenfootImage(Image); for ( int x= 0 ; x<i.getWidth();x++) for ( int y= 0 ; y<i.getHeight();y++) { java.awt.Color C = i.getColorAt(x,y); int brightness = (C.getRed()+C.getGreen()+C.getBlue())/ 3 ; i.setColorAt(x,y, new java.awt.Color ( brightness, brightness, brightness, C.getAlpha())); } return i; } |