获得从一个ImageView的位图图像的坐标的两倍小 [英] Get coordinates of a Bitmap image from an ImageView twice as small

查看:116
本文介绍了获得从一个ImageView的位图图像的坐标的两倍小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ImageView包含的 HTTP ://developer.android.com/reference/android/graphics/Bitmap.html相对=nofollow>位图图像。该图像是两倍大,它的容器。我宣布 onScroll()要能走动的位图图像。我怎样才能获得的ImageView 上的位图形象?

 位图BM = BitmapFactory.de codeResource(getResources(),R.drawable.image);
_iv.setImageBitmap(BM);
_iv.setAdjustViewBounds(真正的);
_iv.setMaxHeight(bm.getHeight());
_iv.setMaxWidth(bm.getWidth());
_iv.setScaleType(ImageView.ScaleType.CENTER);

位图newBm = Bitmap.createScaledBitmap(宽多重峰,bm.getWidth()* 2,bm.getHeight()* 2,真);
_iv.setImageBitmap(newBm);
 

解决方案

我还没有找到一个实际的方式做到这一点。下面是我用的方法:

一旦创建 ImageView的,滚动到一个已知位置。

  INT IVX = 0;
INT常春藤= 0;

_iv.invalidate();
_iv.scrollTo(IVX,IVY);
 

这样,我有确切的(X,Y)坐标我在哪里的。然后,我已经实现了<一href="http://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html#onScroll%28android.view.MotionEvent,%20android.view.MotionEvent,%20float,%20float%29"相对=nofollow> onScroll()的方法和使用所产生的距离来重新计算我的(X,Y)坐标:

  @覆盖
公共布尔onScroll(MotionEvent E1,E2 MotionEvent,浮distanceX,浮distanceY){
    //增加的滚动距离到旧的X,Y坐标
    IVX + = distanceX;
    IVY + = distanceY;

    //滚动到新位置
    _iv.scrollTo(IVX,IVY);

    返回false;
} //结束onScroll()
 

此外,为了更好地了解如何 scrollTo()作品和图像的坐标和它的容器之间的关系,按照这个<一href="http://stackoverflow.com/questions/7773206/where-does-android-view-scrolltox-y-scroll-to/7851835#7851835">link到不同的岗位我的。

I have an ImageView containing a Bitmap image. The image is twice as big as its container. I have declared onScroll() to be able to move around the Bitmap image. How can I get the coordinates of the ImageView on the Bitmap image?

Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);
_iv.setImageBitmap(bm);
_iv.setAdjustViewBounds(true);
_iv.setMaxHeight(bm.getHeight());
_iv.setMaxWidth(bm.getWidth());
_iv.setScaleType(ImageView.ScaleType.CENTER);

Bitmap newBm = Bitmap.createScaledBitmap(bm, bm.getWidth() * 2, bm.getHeight() * 2, true);
_iv.setImageBitmap(newBm);

解决方案

I haven't found an actual way to do this. Here's the method I've used:

Upon creating the ImageView, scroll to a known location.

int ivX = 0;
int ivY = 0;

_iv.invalidate();
_iv.scrollTo(ivX, ivY);

This way I have the exact (x, y) coordinates of where I am. Then, I've implemented the onScroll() method and used the generated distances to recalculate my (x, y) coordinates:

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    //Add the scroll distance to the old X, Y coordinates
    ivX += distanceX;
    ivY += distanceY;

    //Scroll to the new location
    _iv.scrollTo(ivX, ivY);

    return false;
} //End onScroll()

In addition, to get a better understanding of how scrollTo() works and the relationship between the coordinates of the image and its container, follow this link to a different post of mine.

这篇关于获得从一个ImageView的位图图像的坐标的两倍小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆