简体   繁体   中英

Determining if a Java.awt.Rectangle contains a Java.awt.Color

I was wondering how I would determine if a Java.awt.Rectangle contains a pixel that is a specific Java.awt.Color. I've been searching all over but I cannot find any information on this or if it's even possible.

So I was wondering how to determine if a Rectangle contains aa pixel with a specific Color or if a specific colored pixel is inside a defined Rectangle.

Example: The left image is a black rectangle. Lets say I have a defined Java.awt.Color that is red. I want to determine if that rectangle contains a pixel that is that color. 在此处输入图片说明

If you need to find out if some pixel on a Graphics was painted in this color, you can only discover it if the Graphics was created over a BufferedImage. So you could run the same code that draws on screen, say call a Component's paint(Graphics) method, passing to it the result of BufferedImage.createGraphics() call. Once painting is done, check pixel values in the range you need by calling BufferedImage.getRGB(x, y).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM