Finding the colour of a pixel

B

Barry Parker

Within a java applet, so basically on a graphics object, I have various
different shapes. The shapes are a different colour to the background. The
number and location of the shapes will be unknown till compile time.

What I basically think I need to do is, given the cursor position, determine
if the pixel it currently resides on is blue or white. I have tried all
sorts of things but I'm getting nowhere. Simple commands such as getColor()
aren't having any of it.

Its been necessary to make a copy of the graphics object to use within my
MouseListener as it doesn't appear to allow me to pass the graphics object
from the paint method to the listener (this could be a problem: for a
Graphics object called g from within my paint method, I have copied it to
another Graphics object, h, by using h=g.create();) From here, what I
have done is created a 'Clip Area' of 1 pixel by 1 pixel at the current
point which returns a rectangle. Is there any way of getting the colour of a
rectangle?

If anyone has any suggestions, it would be much appreciated as I'm pulling
my hair out over something simple.

Cheers, Baz
 
P

Paul

I know you can get the pixel color of particular screen coordinates using
java.util.Robot, and you may be able to translate from screen coordinates to
your applet's coordinates.
If that won't work, you might try creating an Image or BufferedImage from
your applet's display, and look at java.awt.image.* or javax.imageio.* for
clases to help manipulate the image.
--Paul
 
B

Barry Parker

I have tried to use the Robot but it appears I can't use this, possibly to
do with it being an applet:

java.security.AccessControlException: access denied (java.awt.AWTPermission
createRobot)

Baz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top