static void invertImage(BufferedImage img) { int w = img.getWidth(), h = img.getHeight(); for (int x = 0; x < w; x++) for (int y = 0; y < h; y++) { int rgba = img.getRGB(x, y); Color col = new Color(rgba, true); col = new Color(255-col.getRed(), 255-col.getGreen(), 255-col.getBlue()); img.setRGB(x, y, col.getRGB()); } }