尝试从ImageView的onTouchListener获取位图像素

|| 我在ImageView上显示位图。当点击ImageView时,我想获取点击它的位图的像素x / y坐标。我已经注册了ImageView的onTouchListener,并且在onTouch方法中,我使用getX和getY来获取触摸的位置。问题在于ImageView中的图像可能比视图本身大,因此会按比例缩小以适合屏幕。然后,返回的x和y坐标是视图的坐标,但不一定是位图上相应像素的坐标。 我可以得到某种比例因子来知道调整了多少大小吗?否则,有人可以建议我如何获取所需的信息吗?最重要的是,我可以获取像素坐标-如果必须更改视图类型,没关系。 同样,有时位图比屏幕小,因此它会按比例放大。在这种情况下,从MotionEvent接收到的x和y可能超出实际位图的范围。     
已邀请:
签入ScaleType属性。您必须根据getScaleType()的结果对原始图像进行数学运算,但是值得一试。     
我可以遇到同样的情况。该线程已经使用了一年多,但是认为它可能对某人有用。在设置为ImageView之前,我必须缩放位图。 这是代码:
//Convert Uri to Bitmap
inputBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage);

//Scale the bitmap to fit in the ImageView
Bitmap bmpScaled = Bitmap.createScaledBitmap(inputBitmap, img.getWidth(), img.getHeight(),true);

//Set the scaled bitmap to the ImageView
img.setImageBitmap(bmpScaled);
此后,触摸的坐标与位图的坐标相同。     

要回复问题请先登录注册