[英]Get x,y of image in Imageview onClick() with scale type fitCenter
I have an ImageView, by using image resolution I have placed canvas objects on top of that Image 我有一个ImageView,通过使用图像分辨率,我将画布对象放置在该图像的顶部
when I touched the ImageView it should return x,y of image not Imageview. 当我触摸ImageView时,它应该返回图像的x,y而不是Imageview。 I don't want use FitXY scale type
我不想使用FitXY标度类型
currently I am getting x,y of Imageview 目前我正在获取Imageview的x,y
iv.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
float x = (event.getX())/2; // or getRawX();
float y = (event.getY())/2;
System.out.println("drawn bounds:cx: "+x+"cy: "+y);
return false;
}
});
Please help me to get x,y of image rather than Imageview. 请帮助我获取图像的x,y而不是Imageview。
Try this to get XY of image 尝试获取图像的XY
float bitmapWidth = bitmap.getWidth();
float bitmapHeight = bitmap.getHeight();
float imageWidth = iv.getWidth();
float imageHeight = iv.getHeight();
float proportionateWidth = bitmapWidth / imageWidth;
float proportionateHeight = bitmapHeight / imageHeight;
int tapX = (int) (event.getX() * proportionateWidth);
int tapY = (int) (event.getY() * proportionateHeight);
Hope its help! 希望它的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.