获取您点击JPanel的位置的颜色? [英] Getting the colour of where you have clicked on a JPanel?

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

问题描述

我只想要一个方法激活,如果被点击的像素是白色的。我将如何实现这一点?尝试寻找在协调器处返回颜色的方法,但我找不到一个。

I only want a method to activate if the pixel that is clicked is white. How would I implement this? Trying to look for a method that returns the colour at a coord, but I can't find one.

推荐答案

如果您有 getRGB 方法(或 getRaster()。getPixel )。如果没有,可以使用JPanel的 createImage 方法,并使用返回的图像获取像素数据。

Depends. If you have got a BufferedImage (or some other Image) you can use its getRGB methods (or getRaster().getPixel). If you haven't, you can use JPanel's createImage methods and use the returned image to get the pixel data.

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

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