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();
来源:https://stackoverflow.com/questions/13307962/how-to-get-the-color-of-a-point-in-a-jpanel