1

So here is my problem. I've got an image view containing a large bitmap (meaning that the imageview only shows a part of it since the bitmap is larger than the image view). I want to be able to center the bitmap in the imageview at the coordinates x, y (x and y are coordinate of the bitmap).

Any idea how I could achieve it ?

Regards, Rob

rmonjo
  • 2,675
  • 5
  • 30
  • 37

1 Answers1

0

try with

ImageView.ScaleType FIT_CENTER

see here the documentation http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

now depending on how large is exactly your bitmap you might want to reduce it's size by using something like this

private Bitmap decodeFile(File f) {
    Bitmap b = null;
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(f);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        int scale = 1;
        if (o.outHeight > 1024 || o.outWidth > 900) {
            scale = (int) Math.pow(2, (int) Math.round(Math.log(1024 / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        fis = new FileInputStream(f);
        b = BitmapFactory.decodeStream(fis, null, o2);
        fis.close();
    } catch (IOException e) {
    }
    return b;
}

credits to How to scale bitmap to screen size?

Community
  • 1
  • 1
OWADVL
  • 10,704
  • 7
  • 55
  • 67
  • Hi, thanks. But the thing is that I don't want my bitmap to adjust to the size of the imageview. I just want to be able to move it to the center of the image view given a coordinate. – rmonjo Mar 18 '12 at 17:33