salar
salar

Reputation: 17

getWidth() function in bitmap library of android doesn't return true image height

I wanted to load an .PNG image through my android application by using android.graphics.Bitmap library. I have succeeded to load it but there is some problem i can't figure out.

My image pixel count is 144*144 but when i try to get the width of my loaded image by using getWidth() function, it returns 432 which is 144*3.

This is how i try to load my image:

mBitmapIn = loadBitmap(R.drawable.data);

Where the loadBitmap function is defined as:

private Bitmap loadBitmap(int resource) {
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    return BitmapFactory.decodeResource(getResources(), resource, options);
}

I would appreciate if anybody could help me to find out the reason of it.

Thanks

Upvotes: 1

Views: 397

Answers (1)

x-treme
x-treme

Reputation: 1636

drawable folder is considered to have mdpi's density (which is the baseline density). Nexus 5 has a density of 445ppi which falls under xxhdpi category. Therefore if you read in a bitmap which is not present in drawable-xxhdpi directory, the system will have to find it in another directory and scale it. xxhdpi screens are approximately 3 times as dense as mdpi screens. Since the only drawable folder you have under res is drawable itself, android scales it 3 times along both the dimensions

You can get more information about this here

Upvotes: 1

Related Questions