2

Possible Duplicate:
Android app loading images from /drawables-nodpi/ with scaling

I recently rebuilt my Android project to target 2.2 from 2.1.

In the old project, I did not specify a target SDK (the manifest did not contain something like: android:minSdkVersion="8"). This gave me an error in the console when running, but everything worked fine so I didn't fool with it.

The new project now uses android:minSdkVersion="8" in the manifest.

But now my drawables from the /drawable-nodpi/ folder are loading with scaling, making them much smaller and significantly changing the desired visuals.

If I cut out the tag from my manifest, they load properly without scaling.

Even when loading my images like so:

        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inScaled = false;   
        Bitmap bm = BitmapFactory.decodeResource(_resources, resId, opts);

They are still scaled when I declare the minimum SDK in the manifest, but not scaled if I remove that tag.

Why is this happening? How can I load them without scaling while still declaring the minimum SDK?

Community
  • 1
  • 1
jjj
  • 51
  • 1
  • 2

3 Answers3

1

There is another explanation given here:

"If you don't specify <supports-screens> or minSdk, then your app will run in compatibility mode, meaning that it's given an HVGA (240x320) "virtual screen", which is then scaled as a whole. So your images will be scaled."

The original poster was therefore running their app in this compatibility mode before and the images were automatically scaled up from HVGA to the actual screen resolution; by adding minSdkVersion the images were no longer scaled and therefore appeared smaller.

Craig Heath
  • 566
  • 4
  • 14
0

When you set minsdkversion you are telling Android that the app can work from API level 8, which is Android 2.2. Previously since you didn't specify that, Android knew how to handle assets, but now with minsdkversion line in manifest you are providing guidelines.

Read up on how all assets and assets hierarchy is implemented in Android here and here. This may be not the quick fix answer you want, but it will help you understand Android platform better.

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
omermuhammed
  • 7,365
  • 4
  • 27
  • 40
  • Thank you for the response -- I've spent significant time reading both of those pages already trying to resolve this. It even specifically mentions placing files in the /drawable-nodpi/ folder, which I have done, to avoid scaling. They are still being scaled. Why would android:minSdkVersion="8" cause it to decide that images in the nodpi folder should be scaled, even when all documentation says they will not be? – jjj Oct 19 '10 at 16:56
  • One thing I can think of is you have same assets in hdpi/mdpi/ldpi folder and also in nodpi folder. Based on how Android handles the folder hierarchy it may do that. – omermuhammed Oct 19 '10 at 19:27
  • 2
    All of my graphic assets are in the nodpi folder exclusively. I'm making a game that programatically draws the bitmaps on a surface, and don't have any situation in which they should be scaled for DPI. I've not been able to find any solution to this... Am I okay just leaving the minSdkVersion tag out of my manifest, or will I run into problems when I publish? – jjj Oct 19 '10 at 22:33
  • You should be ok, just test it with different versions of Android. – omermuhammed Oct 19 '10 at 22:43
  • This answer does not explain why the images were scaled when no minSdkVersion was given. It is because of the compatibility mode which is automatically applied in that case. – Craig Heath Dec 08 '16 at 13:58
0

I know this is an ancient question and the answer probably means little to you today, but because I just wrestled with this for a day and a half, I figured I'd throw out the answer for anyone else.

No matter what I did my images would be loaded from resources with a strange scale. I tried all manner of methods, from using Options.inScaled=false to setting inDensity = 160, to even using an InputStream and decoding the bitmap from the stream. Nothing worked... Images that have a raw size of 340x480 always loaded with some weird dimensions like 321x481 no matter what.

I went to look at the source image itself and see what dpi/ppi it was saved at. The image was created at the correct dimensions but its internal ppi was 72. I changed the image to render at 160ppi (which blew up the dimensions) and then scaled the dimensions back down to their origial pixels. Using this new source image, at a 160ppi that matched the 160dpi of the display, it rendered just as expected without any weird scaling.

So remember, if your source images are not intended to scale at all, you should make sure either they are set at a ppi that matches your density or that when you decode the bitmap from the bitmapfactory that the options specifies the ppi that the image itself was created to fill.

scriptocalypse
  • 4,942
  • 2
  • 29
  • 41