Android的:如何在ImageView的检测触摸位置,如果图像视图由矩阵比例? [英] Android: how to detect touch location on ImageView if the image view is scaled by matrix?

查看:313
本文介绍了Android的:如何在ImageView的检测触摸位置,如果图像视图由矩阵比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆