3

I have an ImageView with scaletype set to matrix, and would like to get a Rect with the bounds of the image after the transformation of the matrix.

How do I get such a rect? thanks.

saarraz1
  • 2,999
  • 6
  • 29
  • 44

2 Answers2

12
ImageView imageView = (ImageView)findViewById(R.id.imageview);
Drawable drawable = imageView.getDrawable();
Rect imageBounds = drawable.getBounds();

Then use Matrix.mapRect.

Tomislav Markovski
  • 12,331
  • 7
  • 50
  • 72
  • 2
    So, complete code for me was `Rect bounds = imageView.getDrawable().getBounds(); RectF boundsF = new RectF(bounds); imageView.getImageMatrix().mapRect(boundsF); boundsF.round(bounds);` Thank you, it worked and I finally fixed a transition! – charlag Jun 09 '17 at 07:09
0
ImageView imageView = (ImageView)findViewById(R.id.imageview);

Drawable drawable = imageView.getDrawable(); Rect imageBounds = drawable.getBounds();

this is wrong, this will get the original drawable bound, not the really bound
of bitmap drawn on ImageView