Skip to content Skip to sidebar Skip to footer

Android I Want To Get Different X,y Position On Touch When Canvas Scale And Translation

I want to get current x, y coordinates when i scale and translate canvas, how can i achieve this? When canvas scale and Translate after not get current x y position and i get diffe

Solution 1:

Use this method to get co-ordinates on canvas touch point

final 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;
}

Post a Comment for "Android I Want To Get Different X,y Position On Touch When Canvas Scale And Translation"