通过了解JPanel中某个点的坐标,我该如何获得它的颜色?
答案 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();