By knowing the coordinates of a point in a JPanel, how can I get its color?
Draw the content of the panel inside a Graphics2D
object created from a BufferedImage
and then retrieve the pixel color:
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2 = image.createGraphics();
_mainPanel.paint(g2);
image.getColorModel().getRGB(pixel);
g2.dispose();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With