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

相关内容

热门资讯

透视中牌率!wpk辅助器下载,... 透视中牌率!wpk辅助器下载,wepokerplus作弊,我来教教你(总是有挂);原来确实真的有挂(...
透视美元局!智星菠萝可以辅助吗... 透视美元局!智星菠萝可以辅助吗,wepoker怎么破解游戏,新版2025教程(真是真的是有挂),亲,...
透视透视!hhpoker辅助软... 透视透视!hhpoker辅助软件下载,hhpoker外挂靠谱吗,攻略教程(原先是有挂);亲,其实确实...
透视好友房!wepoker底牌... 【福星临门,好运相随】;透视好友房!wepoker底牌透视脚本,wpk私人局辅助是真的吗,高科技教程...
透视透视挂!德普之星透视辅助,... 透视透视挂!德普之星透视辅助,hhpoker有没有作弊辅助,透明挂教程(最初有挂);亲真的是有正版授...
透视工具!wepoker透视,... 透视工具!wepoker透视,aapoker透视脚本,切实教程(总是是真的有挂);玩家必备必赢加哟《...
透视教程!wepoker辅助下... 透视教程!wepoker辅助下载,aapoker透视插件,解说技巧(素来有挂)关于aapoker透视...
透视有挂!红龙poker透视,... 透视有挂!红龙poker透视,wepoker怎么看牌型,曝光教程(一贯有挂);红龙poker透视最新...
透视实锤!hhpoker辅助软... 透视实锤!hhpoker辅助软件下载,we-poker有人玩吗,必赢方法(其实存在有挂);大神普及一...
透视线上!hhpoker怎么开... 透视线上!hhpoker怎么开透视,wepoker插件功能辅助器,解说技巧(一向存在有挂);原来确实...