我正在研究Android应用程序的Frame multiple layout selection特性。如何获取ImageView中的可见位图的顶部和左侧坐标android
我的要求是在缩放和缩小图像后获取位图的顶部和左侧坐标。
我正在使用TouchImageView进行缩放和移动功能。
我已经尝试了很多SO解决方案,但没有得到我的要求的解决方案。
1日试 -
public static int[] getBitmapOffset(ImageView img, boolean includeLayout) {
int[] offset = new int[2];
float[] values = new float[9];
Matrix m = img.getImageMatrix();
m.getValues(values);
offset[0] = (int) values[5];
offset[1] = (int) values[2];
if (includeLayout) {
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) img.getLayoutParams();
int paddingTop = (int) (img.getPaddingTop());
int paddingLeft = (int) (img.getPaddingLeft());
offset[0] += paddingTop + lp.topMargin;
offset[1] += paddingLeft + lp.leftMargin;
}
return offset;
}
第二次尝试 -
Rect r = img.getDrawable().getBounds();
int drawLeft = r.left;
int drawTop = r.top;
int drawRight = r.right;
int drawBottom = r.bottom;
Logger.logsInfo(TAG, "Focus drawLeft : " + i + " : " +drawLeft);
Logger.logsInfo(TAG, "Focus drawTop : " + i + " : " +drawTop);
Logger.logsInfo(TAG, "Focus drawRight : " + i + " : " +drawRight);
Logger.logsInfo(TAG, "Focus drawBottom : " + i + " : " +drawBottom);
请让我知道我做错了,因为我对这个从过去三天的工作,但仍不能完成。
在此先感谢。 建议非常感谢。退房getZoomedRect
的
得到'img.getDrawingCache() '你会继续可见。在此之前添加'img.setDrawingCacheEnabled(true);' – Qamar
在你的第一次尝试中,你是否尝试过使用'Matrix.postScale(yourScaleFactor,yourScaleFactor)'? –
您正在按矩阵调整图像大小。在'postScale'图像获得新的坐标之后,我认为matrix.mapRect会帮助你。获取视图矩形和映射矩阵,然后离开将指向您预期的x。 – Qamar