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?
GreenfootImage image=getImage(); image.setColor(Color.WHITE); image.fill(); setImage(image);
import java.awt.Color;
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; }