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数组将包含任何特定点在图像中的像素坐标。

相关内容

热门资讯

透视安装"wepok... 透视安装"wepoker脚本"详细辅助微扑克教程(果然真的有挂);玩家必备必赢加哟《13670430...
查到实测!hhpoker有没有... 查到实测!hhpoker有没有外挂,wepoker私局辅助,爆料教程(有挂透视)关于hhpoker有...
透视挂"hhpoke... 透视挂"hhpoker俱乐部是干嘛的"详细辅助必赢方法(起初真的是有挂)准备好在hhpoker俱乐部...
科技通报!cloudpoker... 1、科技通报!cloudpoker怎么开挂,wpk免费辅助,教你攻略(有挂神器)。2、cloudpo...
透视透视挂"hhpo... 透视透视挂"hhpoker辅助靠谱吗"详细辅助技巧教程(原生有挂);最新版2024是一款经典耐玩的益...
必备攻略!wepoker买钻石... 必备攻略!wepoker买钻石有用吗,约局吧辅助器,透明教程(有挂教程);实战中需综合运用上述技巧,...
透视规律"wejok... 《透视规律"wejoker手机版透视脚本"详细辅助2025新版教程(起初真的是有挂)》 wejoke...
科技介绍!wepoker国外版... 1、科技介绍!wepoker国外版透视,约局吧开挂神器是真的吗,细节揭秘(有挂神器)(UU poke...
透视安装"wepok... 透视安装"wepokerplus开挂"详细辅助科技教程(最初真的是有挂);《WPK辅助透视》‌:支持...
玩家攻略!hhpoker真能买... 玩家攻略!hhpoker真能买到挂吗,wepoker私人定制透视,攻略教程(有挂攻略);实战中需综合...