Finding the colour of a pixel

Discussion in 'Java' started by Barry Parker, Jan 25, 2005.

  1. Barry Parker

    Barry Parker Guest

    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
    Barry Parker, Jan 25, 2005
    #1
    1. Advertising

  2. Barry Parker

    Paul Guest

    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" <> wrote in message
    news:ct6b0f$28d$...
    > 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
    >
    >
    Paul, Jan 25, 2005
    #2
    1. Advertising

  3. Barry Parker

    Paul Guest

    That should be java.awt.Robot

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

    ....

    --Paul
    Paul, Jan 25, 2005
    #3
  4. Barry Parker

    Barry Parker Guest

    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
    Barry Parker, Jan 26, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    3
    Views:
    450
    Patrice
    Jun 29, 2005
  2. Johny
    Replies:
    4
    Views:
    356
    Laurent Pointal
    Apr 27, 2007
  3. André Wagner

    Fastest pixel by pixel operation

    André Wagner, Mar 17, 2008, in forum: Java
    Replies:
    12
    Views:
    1,029
    Larry A Barowski
    Mar 19, 2008
  4. pixel colour on screen

    , Jun 28, 2008, in forum: Python
    Replies:
    4
    Views:
    291
    Tim Roberts
    Jul 27, 2008
  5. jodleren
    Replies:
    2
    Views:
    188
    Thomas 'PointedEars' Lahn
    Jan 12, 2008
Loading...

Share This Page