如何获取JPanel中点的颜色? [英] How to get the color of a point in a JPanel?

查看:25
本文介绍了如何获取JPanel中点的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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();

这篇关于如何获取JPanel中点的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆