Android的:如何在ImageView的检测触摸位置,如果图像视图由矩阵比例?矩阵、视图、图像、比例

由网友(有故事的人)分享简介:我设置 OnTouchListener 的ImageView的,实行 onTouch 的方法,但使用矩阵,如果对图像进行缩放,怎么我计算出触控的位置? I set OnTouchListener of an ImageView and implement onTouch method, but if the imag...

我设置 OnTouchListener 的ImageView的,实行 onTouch 的方法,但使用矩阵,如果对图像进行缩放,怎么我计算出触控的位置?

I set OnTouchListener of an ImageView and implement onTouch method, but if the image is scaled using matrix, how do I calculate the location of the touch?

还是运动时返回时会自动考虑到这一点的getX() getY()以

Or does the motion event automatically takes that into account when returning getX() and getY() ?

推荐答案

的getX和会的getY的ImageView的坐标系统中返回触摸位置。如果你正在寻找图像的坐标系内的点,你可以用用的ImageView的矩阵的逆矩阵。我已经做了一些这样的:

getX and getY will return the touch location in the ImageView's coordinate system. If you're looking for the point within the image's coordinate system, you can use the inverse matrix of the matrix used by the ImageView. I've done something like the following:

// calculate inverse matrix
Matrix inverse = new Matrix();
imageView.getImageMatrix().invert(inverse);

// map touch point from ImageView to image
float[] touchPoint = new float[] {event.getX(), event.getY()};
inverse.mapPoints(touchPoint);
// touchPoint now contains x and y in image's coordinate system
阅读全文

相关推荐

最新文章