问题描述
我设置 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
这篇关于Android的:如何在ImageView的检测触摸位置,如果图像视图由矩阵比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!