[英]How to take real coordinates(X,Y) of Bitmap from imageView Android
i have little problem. 我没什么问题。
I'm getting an image,converting to Bitmap and fill imageview with this Bitmap . 我正在获取图像,转换为Bitmap并使用此Bitmap填充imageview。
So the problem is,how to take real coordinates(X,Y) of this Bitmap? 所以问题是如何获取该位图的真实坐标(X,Y)?
For better illustration, i attached an image: 为了更好地说明,我附上了一张图片:
As shown on picture, for eg i got an image with Custom Resolution,where user can make an perspective , via yellow points. 如图所示,例如,我得到了一个具有“自定义分辨率”的图像,用户可以在其中通过黄点进行透视 。
So i need to know,how to take real coords of bitmap from ImageView. 所以我需要知道如何从ImageView中获取位图的真实坐标。
What i've made at current moment(but this approach isn't correct): 我目前所做的事情(但是这种方法不正确):
i take width / height from imageView and recreating new bitmap with this resolution. 我从imageView中获取宽度 / 高度 ,并以此分辨率重新创建新的位图。
Bitmap bt = Bitmap.CreateScaledBitmap(BitmapFactory.DecodeResource(Activity.Resources, Resource.Drawable.test),800,1420,false); //800 width 1420 height
imgView.SetImageBitmap(bt);
Via implementation of TouchListener (methods GetX() / GetY() ),i get coords of points(yellow circle's that overlayed on Bitmap), and the problem is that these coordinates not correct. 通过实现TouchListener (方法GetX() / GetY() ),我获得了点的坐标(叠加在Bitmap上的黄色圆圈),并且问题是这些坐标不正确。
Also its interesting for me case when i'm stretching bitmap via ScaleType.FitXY on imageView(its possible to take real coords of bitmap) ? 当我在ImageView上通过ScaleType.FitXY拉伸位图时,这对我来说也很有趣(它可以获取位图的实际坐标)?
So how can i achieve my goal? 那我怎样才能实现我的目标呢?
use ImageView#getImageMatrix
, something like this: 使用ImageView#getImageMatrix
,如下所示:
final ImageView iv = new ImageView(this);
setContentView(iv);
// setup your image here by
// calling for example iv.setImageBitmap()
// or iv.setImageDrawable()
// or iv.setImageResource()
View.OnTouchListener otl = new View.OnTouchListener() {
Matrix inverse = new Matrix();
@Override
public boolean onTouch(View v, MotionEvent event) {
iv.getImageMatrix().invert(inverse);
float[] pts = {
event.getX(), event.getY()
};
inverse.mapPoints(pts);
Log.d(TAG, "onTouch x: " + Math.floor(pts[0]) + ", y: " + Math.floor(pts[1]));
return false;
}
};
iv.setOnTouchListener(otl);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.