saarraz1
saarraz1

Reputation: 3029

Android how to get bounds of imageview with matrix

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.

Upvotes: 3

Views: 6499

Answers (2)

XiaoJun Li
XiaoJun Li

Reputation: 1

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

Upvotes: 0

Tomislav Markovski
Tomislav Markovski

Reputation: 12346

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

Then use Matrix.mapRect.

Upvotes: 12

Related Questions