wizoleliam
wizoleliam

Reputation: 83

why getBounds( ) of Drawable remains the same even after scaling?

I used an ImageView to display a jpg file under my project 'assets' folder, the intrinsic dimensions are: 1280x854, which I confirmed by calling myDrawable.getIntrinsicWidth() and myDrawable.getIntrinsicHeight().

My image view implemented pinch zoom so the image was scaled up to 2x for example. Then the following code got executed:

Drawable drawable = getDrawable();
Rect bounds =drawable.getBounds();
Log.i("activity", String.format("drawalbe : top:%d, left: %d, (%d, %d)", bounds.top, bounds.left, bounds.width(), bounds.height())); 

the drawable bounds is always 1280x854 no matter what the current scale is, and the top, left is always 0, 0.

Isn't the bounds should be scaled accordingly? Could anyone give me some hints? Thank you.

Upvotes: 1

Views: 1266

Answers (1)

SGal
SGal

Reputation: 1082

It's because of this.

Scale matrix only affects how the view is drawn, but does not change its dimensions.

Although you can create a Rect of the size of your image and apply the same scale matrix to Rect with Matrix.mapRect(Rect r) and Rect will have the scaled dimensions.

Upvotes: 1

Related Questions