0

See these other two questions for reference:

Get drawable displayed size after scaling

Trying to get the display size of an image in an ImageView

I can now get the size of the scaled image, but I want to also know the origin (0,0) of the scaled image inside of the image view. In other words, what x,y location inside of image #1 corresponds to 0,0 of image #2?

http://image.noelshack.com/fichiers/2013/06/1360144144-sans-titre.png

Community
  • 1
  • 1
mtbomb
  • 1,107
  • 1
  • 13
  • 16

2 Answers2

1

If you want to know how (0,0) of drawable coresponds to (x,y) of the imageView, you can map points using imageView's transformation matrix like so

float[] drawableCoords = new float[] {0, 0};
imageView.getImageMatrix().mapPoints(drawableCoords);
float onViewX = drawableCoords[0];
float onViewY = drawableCoords[1];

you can also reverse the process (to map from imageView coordinates to drawable coordinates by creating inverted matrix and maping points on it

float[] viewCoords= new float[] {0, 0};
Matrix invertedMatrix = new Matrix()
imageView.getImageMatrix().invert(invertedMatrix);
invertedMatrix.mapPoints(viewCoords);
float onDrawableX= viewCoords[0];
float onDrawableY= viewCoords[1];

Note that transformed coordinates in certain cases can have a negative coordinate value if drawable is smaller/bigger than imageview.

SGal
  • 1,072
  • 12
  • 13
0

I am assuming Image #1 is the parentview to Image #2.

int x = image2.getLeft();
int y = image2.getTop();

will return x,y of the pixel coordinates relative to image2's parentview, image1.

frogmanx
  • 2,620
  • 1
  • 18
  • 20
  • No, #1 is the image view, but the actual bitmap shows up where #2 is. I wouldn't be able to call getLeft on image2 since it's a part of the image1 ImageView. – mtbomb Sep 24 '13 at 05:16