android – 如果我移动并通过捏合,拖动和缩放调整图像大小,我怎么知道我的图像在哪里触摸过

我有一个图像,我用它作为图像映射.如果图像是固定的那么没有问题,但我需要缩放和拖动这个图像,并获得并使用图像点击的坐标.

我是否需要准确跟踪此图像移动的大小和已调整大小,或者我是否可以获得图像的0x0点(图像的左上角).

还有另一种方法吗?

我应该在这个优秀的教程http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2/1747?tag=rbxccnbzd1上添加我的图像处理

最佳答案 您可以使用应用于图像的相同变换矩阵来获取该点.您希望将屏幕坐标系之间的点转换为图像的坐标系,从而反转原始矩阵的效果.

具体来说,您希望使用用于将图像转换到屏幕上的矩阵的反转,将用户在屏幕上单击的x,y坐标转换为原始图像中的对应点.

假设矩阵包含应用于图像的变换的一些伪代码:

// pretend user clicked the screen at {20.0, 15.0}
float x = 20.0;
float y = 15.0;

float[] pts[2];

pts[0] = x;
pts[1] = y;

// get the inverse of the transformation matrix
// (a matrix that transforms back from destination to source)
Matrix inverse = new Matrix();
if(matrix.invert(inverse)) {

    // apply the inverse transformation to the points
    inverse.mapPoints(pts);

    // now pts[0] is x relative to image left
    //     pts[1] is y relative to image top
}
点赞