[英]How to get the origin for drawable image in an imageview
请参阅其他两个问题以供参考:
现在可以获取缩放图像的大小,但是我也想知道图像视图内部缩放图像的原点(0,0)。 换句话说,图像#1内的x,y位置对应于图像#2的0,0?
http://image.noelshack.com/fichiers/2013/06/1360144144-sans-titre.png
如果您想知道(0,0)的可绘制核心如何对应于imageView的(x,y),则可以使用imageView的变换矩阵来映射点,如下所示
float[] drawableCoords = new float[] {0, 0};
imageView.getImageMatrix().mapPoints(drawableCoords);
float onViewX = drawableCoords[0];
float onViewY = drawableCoords[1];
您还可以反转该过程(通过创建倒置矩阵并在其上映射点,将图像从ViewView坐标映射到可绘制坐标
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];
请注意,在某些情况下,如果drawable小于/大于imageview,则转换后的坐标可以具有负坐标值。
我假设图像#1是图像#2的父视图。
int x = image2.getLeft();
int y = image2.getTop();
将返回相对于image2的父视图image1的像素坐标的x,y。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.