Results 1 to 4 of 4
  1. #1
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Red face Coordinates out of bounds

    Hey, im struggling trying to find a rough algorithm to get the colour of a pixel from where the mouse has clicked on an image, below is some of the code im working on :
    Java Code:
    
    //locations clicked
    int pixelX,pixelY;
    
    //make the value = area clicked - the position of the image
    pixelX = e.getX() - imageXposition;
    pixelY = e.getY() - imageYposition;
    
    // get the pixel that was clicked on
    image.getRGB(pixelX, pixelY);
    So far it produces odd results, sometimes the results are negative numbers, Im really just looking for a way to check the RGB value anywhere clicked only within the image. Sometimes because of the erratic results of pixelX and y i get an error that the coordinates are out of bounds because the area on an image of 30 pixels cant reach 150. Any help would be fantastic :)
    Last edited by trishtren; 05-16-2011 at 07:35 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,956
    Rep Power
    8

    Default

    We can't really help you without knowing where/how you're placing the image on the screen, what Component has that MouseListener, etc. If you want help, I'd suggest you provide an SSCCE that demonstrates the problem.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    sometimes the results are negative numbers
    Why do you think that's a problem?

    db

  4. #4
    trishtren is offline Member
    Join Date
    Feb 2011
    Posts
    53
    Rep Power
    0

    Default

    After trying a number of ways to fix it i ended up solving the problem using an if condition to make sure that all the coordinates had to be > than 0 and less than the width of the image that was selected, thanks for taking a look anyway guys :)

Similar Threads

  1. Coordinates in PDFBox
    By arunsegar in forum Advanced Java
    Replies: 1
    Last Post: 05-16-2011, 09:41 AM
  2. Help Getting Image Coordinates
    By Witik in forum New To Java
    Replies: 2
    Last Post: 09-06-2010, 01:02 PM
  3. Coordinates
    By Witik in forum New To Java
    Replies: 3
    Last Post: 09-06-2010, 07:05 AM
  4. Getting mouse coordinates
    By nishant.4545 in forum Advanced Java
    Replies: 3
    Last Post: 07-20-2009, 11:28 PM
  5. button coordinates
    By jacline in forum AWT / Swing
    Replies: 2
    Last Post: 04-05-2009, 10:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •