请参阅另外两个问题以供引用:
Get drawable displayed size after scaling
Trying to get the display size of an image in an ImageView
我现在可以获得缩放图像的大小,但我还想知道 ImageView 内缩放图像的原点 (0,0)。换句话说,图像 #1 内的哪个 x,y 位置对应于图像 #2 的 0,0?
http://image.noelshack.com/fichiers/2013/06/1360144144-sans-titre.png
最佳答案
如果你想知道drawable的(0,0)如何对应imageView的(x,y),你可以像这样使用imageView的变换矩阵来映射点
float[] drawableCoords = new float[] {0, 0};
imageView.getImageMatrix().mapPoints(drawableCoords);
float onViewX = drawableCoords[0];
float onViewY = drawableCoords[1];
您还可以反转该过程(通过创建倒置矩阵并在其上映射点来从 imageView 坐标映射到可绘制坐标
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];
请注意,如果可绘制对象小于/大于 imageview,则在某些情况下转换后的坐标可能具有负坐标值。
关于java - 如何获取 ImageView 中可绘制图像的原点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18971864/