简体   繁体   English

如何从imageView Android获取位图的真实坐标(X,Y)

[英]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.

相关问题 如何在android中的imageview中获取图像的x和y坐标? - How to get x and y coordinates of image inside an imageview in android? 如何在Android中的不同设备和密度上获取imageview的x,y坐标 - How to get x,y coordinates of an imageview on different devices and densities in Android 如何在Android中获取imageview的所有x和y坐标? - How to get all x and y coordinates of an imageview in Android? Android SDK设置ImageView的XY坐标 - android sdk set imageview x y coordinates 如何知道ImageView的X和Y坐标? - How to know the X and Y coordinates of a ImageView? 绝对布局中的ImageView,如何设置ImageView的x,y坐标? - ImageView within an AbsoluteLayout, How to set x, y coordinates of the ImageView? Android:如何获取图像/ ImageView中的xy坐标? - Android: How do I get the x y coordinates within an image / ImageView? Android:如何从(x,y)坐标计算图像的纬度和经度? - Android:How to calculate latitude and longitude of an image from (x,y) coordinates? 如何在ImageView中在Android中将OnTouchEvent坐标转换/缩放到位图画布上 - How to translate/scale OnTouchEvent coordinates onto bitmap canvas in Android in ImageView 如何在 PhotoVIew 中缩放(缩放和移动)位图的 x、y 坐标? - How to scale (zoom and move) to x,y coordinates of Bitmap in PhotoVIew?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM