【问题标题】:Android: MotionEvent's x and y pixel do not translate to image coordinatesAndroid:MotionEvent 的 x 和 y 像素不会转换为图像坐标
【发布时间】:2013-04-04 18:16:42
【问题描述】:

我在 MotionEvent 中使用 getX() 和 getY() 函数来获取用户触摸屏幕的 x 和 y 位置。我也在使用安卓相机拍摄图像。这些图像是 480x640。我的意图是让用户绘制一个框并获取开始和结束 x,y 位置并使用它们创建一个框并裁剪图像。 不幸的是,即使用户使用 android 屏幕(显示来自摄像头的视频)将正确的区域框起来,MotionEvent 的坐标也与图像上的正确位置完全不相关。有时我从 MotionEvent 获得的 x,y 坐标实际上超过 480 或 640。 android屏幕的尺寸与图像的尺寸不同吗?或者 MotionEvent 中的 x,y 位置是否对应于其他东西

【问题讨论】:

标签: android camera touch coordinates motionevent


【解决方案1】:

返回的坐标取决于所使用的指针,但通常是屏幕坐标,因此要从视图获取相对坐标,您需要偏移视图位置。

见:

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

对于视图的偏移使用:

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

【讨论】:

  • 没用。它实际上会导致应用程序崩溃。我发现我的问题只是拍摄的图像和应用程序屏幕之间的分辨率差异。无论如何,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-09
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多