How to determine what color is on a certain pixel?

Is there a way to get the color that is on a certain pixel of an Image using the Graphics objet or Image (/BufferedImage) object itself?

Yes, by using BufferedImage.

Thats how u do it:

  1. get a Graphics2D object: g2d = yourBufferedImage.createGraphics();
  2. draw your image on the BufferedImage
  3. get the color of a pixel: int colorCandidate = yourBufferedImage.getRGB(x,y);

How do I convert the colorCandidate into a Color-object?


Color color = new Color(colorCandidate)

If your image contains alpha-pixels they will blend with your BufferedImage when you draw it to it.
To copy the pixels without blending set the alpha composite of the BufferedImage’s Graphics object to SRC:


g2d.setComposite(AlphaComposite.Src);