Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Finding the colour of a pixel

Reply
Thread Tools

Finding the colour of a pixel

 
 
Barry Parker
Guest
Posts: n/a
 
      01-25-2005
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


 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      01-25-2005
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

"Barry Parker" <(E-Mail Removed)> wrote in message
news:ct6b0f$28d$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Paul
Guest
Posts: n/a
 
      01-25-2005
That should be java.awt.Robot

>I know you can get the pixel color of particular screen coordinates using
>java.util.Robot,

....

--Paul


 
Reply With Quote
 
Barry Parker
Guest
Posts: n/a
 
      01-26-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Fuji S3000 - 3.2 m/pixel or 6 m/pixel? Peter H Digital Photography 3 11-18-2003 11:17 PM
Re: Pixel size of individual Pixel Robert E. Williams Digital Photography 2 09-16-2003 03:02 PM
Re: Pixel size of individual Pixel Tom Thackrey Digital Photography 2 09-14-2003 04:17 PM
Hot pixel vs. stuck pixel Abrasha Digital Photography 5 09-02-2003 04:49 PM



Advertisments