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

相关内容

热门资讯

4分钟了解!微扑克ai软件!其... 4分钟了解!微扑克ai软件!其实是真的有挂((2024已更新))(哔哩哔哩);微扑克ai黑科技是一款...
透视软件!全民雀神云南临沧下载... 透视软件!全民雀神云南临沧下载(辅助挂)确实是真的有挂(真的有挂)-哔哩哔哩;全民雀神云南临沧下载是...
玩家必看科普!大众互娱麻将软挂... 玩家必看科普!大众互娱麻将软挂神器(辅助挂)竟然真的有挂(讲解有挂)-哔哩哔哩;大众互娱麻将软挂神器...
两分钟科普!wepower插件... 两分钟科普!wepower插件(透视)软件透明挂((2021已更新))(哔哩哔哩)是一款可以让一直输...
透明新版!微扑克模拟器是什么!... 1、透明新版!微扑克模拟器是什么!其实是真的有挂((2025已更新))(哔哩哔哩);该软件可以轻松地...
关于!决战卡五星有没有银牌的秘... 自定义决战卡五星有没有银牌的秘诀系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅...
技术分享!微信雀神广东麻将提高... 技术分享!微信雀神广东麻将提高胜率技巧(辅助挂)竟然是真的有挂(有挂透明挂)-哔哩哔哩;玩家必备必赢...
7分钟攻略!wpk线上实战(透... 7分钟攻略!wpk线上实战(透视)辅助透视((2024已更新))(哔哩哔哩)是一款可以让一直输的玩家...
推荐一款!wepoke 软件!... 推荐一款!wepoke 软件!的确真的有挂((2025已更新))(哔哩哔哩)关于wepoke机制的,...
揭秘!雀神微信小程序开挂(辅助... 大家肯定在之前雀神微信小程序开挂或者雀神微信小程序开挂中玩过揭秘!雀神微信小程序开挂(辅助挂)竟然真...