0

I am using the getX() and getY() functions in MotionEvent to get the x and y positions of where the user touched the screen. I am also capturing images using the android camera. These images are 480x640. My intention is to use have the user draw a box and the get the start and end x,y positions and use them to create a box and crop the image. Unfortunately, even if the user boxes the correct area using the android screen (which shows video from the camera), the coordinates from MotionEvent do not relate at all to the correct location on the image. Sometimes the x,y coordinates I get from the MotionEvent are actually more than 480 or 640. Are the dimensions of the android screen different than the image's? Or do the x,y positions from MotionEvent correspond to something else

Nageen
  • 31
  • 1
  • 6

1 Answers1

0

The coordinates returned depend on the pointer being used but in general are in screen coordinates, so to get the coordinates relative from the view you need to offset by the views position.

See:

http://developer.android.com/reference/android/view/MotionEvent.html#AXIS_X

For offset of the view use:

https://developer.android.com/reference/android/view/View.html#getLeft() https://developer.android.com/reference/android/view/View.html#getTop()

Nick Palmer
  • 2,589
  • 1
  • 25
  • 34
  • Didn't work. It actually causes the app to crash. I figured out that my problem was just resolution differences between the image taken and the app screen. Anyway, thanks! – Nageen Apr 09 '13 at 18:12