Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am writing a MouseListener click event, when I click on a JLabel it will give me the RGB value of the pixel that I clicked.

I can use

mybufferedImage.getRGB(e.getPoint().x, e.getPoint().y

However, I am having trouble retrieving the Icon as a BufferedImage.

I KNOW that I can retrieve the Icon and then convert to BufferedImage, but I am wondering if there is an equivalent way of getting the RGB value of the Icon without having to convert to BufferedImage? My main concern is performance, every time I retrieve the RGB value I don't want to have to convert the entire image, especially when I am working with very large images.

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
278 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use the Robot.getPixelColor(...) method to get the pixel color at a given point on the screen.

You will first need to convert the mouse point to a point on the screen using the SwingUtilities.convertPointToScreen(...) method.

My main concern is performance,

Not really an issue. I mean how fast can you click the mouse?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...