ImageView的坐标转换为图片实际的坐标

来源:互联网 发布:网络购物人群分析 编辑:程序博客网 时间:2024/06/07 01:46
</pre><pre name="code" class="html">// 比如我们点击图片得到的 x y 坐标是ImageView的坐标,但是我们需要的是点击的 x y 是图片的坐标
// 用这个方法就可以把ImageView的绝对坐标转换为ImageView里面图片的实际坐标点
// 例如你要在一张图像上画线,并且这个图像是可以放大缩小
public float[] getPointerCoords(ImageView view, MotionEvent e){    final int index = e.getActionIndex();    final float[] coords = new float[] { e.getX(index), e.getY(index) };    Matrix matrix = new Matrix();    view.getImageMatrix().invert(matrix);    matrix.postTranslate(view.getScrollX(), view.getScrollY());    matrix.mapPoints(coords);    return coords;}


0 0
原创粉丝点击