Android: Find absolute click position on the ImageView after zooming (using pinch to zoom using Matrix Layout)

烂漫一生 提交于 2019-12-03 08:48:35

You can use the matrix that is currently applied to the imageview to map points to/from the original default points.

//points from a touch/click event on the zoomed/translated imageview
float X;
float Y;

float initialPoints = new float[]{X, Y};

//invert the matrix and map points back
    if(transformMatrix.invert(inverseTransformMatrix))
            inverseTransformMatrix.mapPoints(initialFocalPoints);

initialPoints now contains the original points, i.e where the click point would be if no matrix was applied to the imageview

EDIT: should have added this in there somewhere so you know what they are.

Matrix inverseTransformMatrix = new Matrix();
Matrix transformMatrix = new Matrix();

Apply the below logic

float[] values = new float[9];
matrix.getValues(values);

calculate scalefactor before pinchzoom;

scaleX=values[0];
scaleY=vales[4];

Now calculate the relative touch coordinates according to iamge after pinch zoom

float relativeX = ((event.getX() - values[2])*sacleX) / values[0];
float relativeY = ((event.getY() - values[5])*scaleY) / values[4];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!