如何获取JPanel中某个点的颜色?

时间:2012-11-09 12:19:32

标签: java swing graphics colors jpanel

通过了解JPanel中某个点的坐标,我该如何获得它的颜色?

1 个答案:

答案 0 :(得分:4)

Graphics2D创建的BufferedImage对象中绘制面板内容,然后检索像素颜色:

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2 = image.createGraphics();
_mainPanel.paint(g2);
image.getColorModel().getRGB(pixel);
g2.dispose();