Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the color of a point in a JPanel? [closed]

By knowing the coordinates of a point in a JPanel, how can I get its color?

like image 998
moorara Avatar asked Oct 06 '22 01:10

moorara


1 Answers

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();
like image 121
Dan D. Avatar answered Oct 10 '22 03:10

Dan D.