Results 1 to 3 of 3
  1. #1
    trishtren is offline Member
    Join Date
    Feb 2011
    Rep Power

    Smile Check if image contains mouse

    Hey, iv been trying to find a simple way to check if an image has been clicked, So far i have been using the following method below :
    Java Code:
           //draw the image 
    	Rectangle imagebox = new Rectangle(30, 30,30, 30);
    	TexturePaint imagepaint = new TexturePaint(image,imagebox);
            //if anchor rectangle contains mouse.getx and mouse.getY perform print
    	if (imagepaint.getAnchorRect().contains(e.getX(),e.getY()))
    		System.out.println("Image clicked");			
    Im looking for a method of checking the image was clicked that does not use a rectangle, as this means you can click anywhere within a box and the image is selected, id prefer to create a shape from the image loaded, however this involves a moderately large amount of code to generate a shape based on pixel alignment. Any help in making it possible to select an image only if its pixels are clicked would be great :)

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    BufferedImage has a method getRGB(int x, int y) that might be useful for that.


  3. #3
    trishtren is offline Member
    Join Date
    Feb 2011
    Rep Power


    That really helped, i have nearly fixed the problem i just need a way to transfer mouse coordinates into image coordinates and itll work, Thanks again!

Similar Threads

  1. how to move an image automatically without using mouse
    By saranyabaskaran in forum New To Java
    Replies: 6
    Last Post: 03-19-2011, 11:00 AM
  2. Show image on glasspane while mouse button is down
    By zweibieren in forum AWT / Swing
    Replies: 10
    Last Post: 09-12-2009, 07:29 AM
  3. Mouse Event + Image Thresholding
    By ojmayolebron in forum AWT / Swing
    Replies: 0
    Last Post: 03-27-2009, 01:17 AM
  4. Image cropping in Jsf on the release of mouse
    By HarshalAuro in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 11-12-2008, 07:24 PM
  5. Replies: 1
    Last Post: 08-25-2008, 09:48 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