/** * Sets the color of a pixel. * * @param i the pixel index * @param color the new color for the pixel */ public void setColorAt(int i, Color color) { if (image == null || i < 0 || i >= pixels()) { throw new IndexOutOfBoundsException("" + i); } else { setColorAt(i % image.getWidth(), i / image.getWidth(), color); } }
public static void main(String[] args) { Picture pic = new Picture(); pic.load("queen-mary.png"); for (int x = 0; x < pic.getWidth(); x++) { for (int y = 0; y < pic.getHeight(); y++) { Color original = pic.getColorAt(x, y); Color negative = new Color(255 - original.getRed(), 255 - original.getGreen(), 255 - original.getBlue()); pic.setColorAt(x, y, negative); } } }