Getting the colour of where you have clicked on a JPanel?

匆匆过客 提交于 2019-12-22 18:27:12

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2623351/getting-the-colour-of-where-you-have-clicked-on-a-jpanel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!