Android中点击ImageView,获取点击的点在Bitmap上对应的坐标

 

 

@Override
public void onSingleTap(MotionEvent e) {
    // 获取触摸点的坐标 x, y
    float x = e.getX();
    float y = e.getY();
    // 目标点的坐标
    float dst[] = new float[2];
    // 获取到ImageView的matrix
    Matrix imageMatrix = imageView.getImageMatrix();
    // 创建一个逆矩阵
    Matrix inverseMatrix = new Matrix();
    // 求逆,逆矩阵被赋值
    imageMatrix.invert(inverseMatrix);
    // 通过逆矩阵映射得到目标点 dst 的值
    inverseMatrix.mapPoints(dst, new float[]{x, y});
    float dstX = dst[0];
    float dstY = dsy[1];
    // 判断dstX, dstY在Bitmap上的位置即可
}

出处:https://blog.csdn.net/afei__/article/details/80155303

posted @ 2019-07-15 01:10  蜜铀  阅读(763)  评论(0编辑  收藏  举报