Reputation: 32273
I'm initializing a Drawable like this:
Drawable drawable = new BitmapDrawable(bitmap);
The dimensions of the bitmap are 50 x 77 (confirmed with the debugger, this values are set in the fields mWidth and mHeight).
But my drawable initializes size 33 x 51, why is this?
I examined the drawable variable just after this line, the values are:
mBitmapWidth = 33
mBitmapHeight = 51
And
drawable.getIntrinsicWidth();
drawable.getIntrinsicHeight();
also returns 33 x 51.
But the drawable also has the bitmap field mBitmap, which has the correct size 50 x 77. So why is the drawable being initialized with 33 x 51?
Upvotes: 2
Views: 512
Reputation: 18670
The dimensions of the Bitmap
are in pixels whereas the dimensions of the Drawable
are in dp (density dependent pixels).
In your case, the density of your display is probably something like 1.5:
50 / 33 = 77 / 51 = 1.5
Note that the drawable dimensions are updated when settings the density via setTargetDensity
method.
Upvotes: 3
Reputation: 13474
BitmapDrawable
adjusts the dimension of your Bitmap to the density of your device.
Note that the constructor you are using is deprecated and that the documentation recommends using BitmapDrawable(Resources res, Bitmap bitmap)
Upvotes: 2