0

In a Java Swing panel I draw an image with arbitrary transfomation e.g.:

public void paintComponent(Graphics g){
    AffineTransform transform = AffineTransform.getTranslateInstance(x, y);
    AffineTransform rotateInstance AffineTransform.getRotateInstance(rotX, rotY);           
    transform.concatenate(rotateInstance);

    g.setTransform(transform);    
    g.drawImage(image, 0, 0 , null);
}

What is the best way to detect mouse over on such an image?

Even better: the best way to detect mouse over only on non-transparent pixels?

Codev
  • 1,040
  • 2
  • 14
  • 31

1 Answers1

1

Construct a Shape that encloses the image, and use the AffineTransform method createTransformedShape() to rotate the Shape along with the image. The Shape method contains() will allow for position testing in Component relative coordinates. Complete examples are seen here and here. Two approaches to inverse coordinate transformation are cited here.

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045