Reputation: 906
I have a 1280x720px image in the res/drawable folder (not the drawable-hdpi, drawable-ldpi, etc. folder). But at runtime the size is 2560x1440px. How is this possible? Does android resize the images in the drawable folder?
Here is the code:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.start_image_left);
int h = bitmap.getHeight(), w = bitmap.getWidth();
I'm testing this on a Motorola Moto G gen2.
Upvotes: 5
Views: 2996
Reputation: 1076
You are correct, Android automatically scales your image based on the current device configuration. If however, you dont want that behaviour, you can create a bitmap resource file, put in the drawable
folder and point it to the drawable you want to use like this
<bitmap xmlns:android="http://schemas.android.com/apk/res/android
android:src="@drawable/yourDrawableHere"
android:gravity="center" />
By specifying the center gravity, android will not scale your image no matter what.
To use this bitmap resource file, in your code, retrieve it like this
Drawable drawable = getResources().getDrawable(R.drawable.yourBitmaoResourceFileName);
Upvotes: 0
Reputation: 134664
There's really no reason you should ever put a bitmap into the root drawable
directory. It should typically be used for XML drawables only. Bitmaps in the drawable
directory will essentially be handled as if they were in drawable-mdpi
(scaled up proportionally for other densities).
If your goal is to have a bitmap image that is the same pixel size on all densities, you need to put it in drawable-nodpi
. This will cause it to not be scaled.
Upvotes: 10