Android-缩放后从ImageView获取原始X和Y点
创始人
2024-08-19 22:00:46
0

要在缩放后从ImageView获取原始X和Y坐标,需要先将ImageView中的坐标转换为实际的位图像素坐标。可以使用以下方法:

  1. 获取ImageView中心点的坐标

int[] imageViewLocation = new int[2]; imageView.getLocationOnScreen(imageViewLocation); int imageViewX = imageViewLocation[0] + imageView.getWidth() / 2; int imageViewY = imageViewLocation[1] + imageView.getHeight() / 2;

  1. 获取ImageView的缩放比例

float scaleFactor = imageView.getScaleX();

  1. 将实际坐标计算为像素坐标

int drawableWidth = imageView.getDrawable().getIntrinsicWidth(); int drawableHeight = imageView.getDrawable().getIntrinsicHeight(); int bitmapWidth = imageView.getDrawable().getBounds().width(); int bitmapHeight = imageView.getDrawable().getBounds().height();

float actualImageWidth = drawableWidth * scaleFactor; float actualImageHeight = drawableHeight * scaleFactor;

float xPercentage = (imageViewX - imageViewLocation[0]) / (float)imageView.getWidth(); float yPercentage = (imageViewY - imageViewLocation[1]) / (float)imageView.getHeight();

float xInImage = xPercentage * actualImageWidth; float yInImage = yPercentage * actualImageHeight;

  1. 对于任何特定的点,可以使用以下代码获取其在图像中的位置:

float[] point = new float[] {xInImage, yInImage}; Matrix matrix = imageView.getImageMatrix(); matrix.invert(matrix); matrix.mapPoints(point);

现在,point数组将包含任何特定点在图像中的像素坐标。

相关内容

热门资讯

透视小程序!wepoker线上... 透视小程序!wepoker线上大神(透视)开挂辅助攻略(一贯有挂)-哔哩哔哩透视小程序!wepoke...
透视代打!wepoker高级辅... 透视代打!wepoker高级辅助,hhpoker脚本,攻略教程(好像是真的挂)-哔哩哔哩1、起透看视...
透视ios!wepoker安装... 透视ios!wepoker安装教程(透视)开挂辅助工具(本来真的是有挂)-哔哩哔哩1、超多福利:超高...
透视教程!sohoo开挂辅助,... 透视教程!sohoo开挂辅助,wepoker公共底牌,手筋教程(确实是有挂)-哔哩哔哩一、wepok...
透视自建房!佛手在线大菠萝技巧... 透视自建房!佛手在线大菠萝技巧(透视)开挂辅助神器(一贯是真的挂)-哔哩哔哩佛手在线大菠萝技巧是一种...
透视规律!wpk私人局辅助是真... 透视规律!wpk私人局辅助是真的吗,wepoker网页版透视方法,指南教程(原来真的有挂)-哔哩哔哩...
透视必备!黑侠破解wepoke... 透视必备!黑侠破解wepoker(透视)开挂辅助方法(原来真的是有挂)-哔哩哔哩黑侠破解wepoke...
透视辅助!wepoker底牌透... 透视辅助!wepoker底牌透视,wpk透视是真的吗,资料教程(好像是真的挂)-哔哩哔哩1、实时wp...
透视神器!wepoker破解是... 透视神器!wepoker破解是真的还是假的(透视)开挂辅助方法(原来真的是有挂)-哔哩哔哩进入游戏-...
透视app!sohoo竞技联盟... 透视app!sohoo竞技联盟辅助器,wepoker透视脚本免费使用视频,教程书教程(本来存在有挂)...