Home > DeveloperSection > Forums > Configure ImageView to display subrect of bitmap in Android
Kamlakar Singh
Kamlakar Singh

Total Post:28

Posted on    November-07-2014 3:47 AM

 Android Image View 

 1 Reply(s)
 954  View(s)
Rate this:

Hi Guys

I have a view that contains an ImageView. The ImageView is populated with a png resource, and fills the width and height of the image view.

Instead of this configuration, I would like to display the image zoomed in by an arbitrary percentage, and translated by an arbitrary coordinate. My question is, how can I configure an image view to display a sub-region of it's src bitmap, with arbitrary translation?

I would really appreciate your help.


Chris S
Chris S

Total Post:48

Posted on    November-07-2014 6:03 AM

You can do this with matrix scaleType

  1. Make a ImageView to have matrix scaleType, android:scaleType="matrix"
  2. Create and manipulate a Matrix like this,

    Matrix matrix = new Matrix();
    matrix.postTranslate(-10, -10);
    matrix.postScale(2, 2);

  3. set this matrix to ImageView, imageView.setImageMatrix(matrix)

Don't want to miss updates? Please click the below button!

Follow MindStick