File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes Resizing Android Bitmap Resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Resizing Android Bitmap Resources" Watch "Resizing Android Bitmap Resources" New topic
Author

Resizing Android Bitmap Resources

Stephen Bell
Ranch Hand

Joined: May 11, 2013
Posts: 35
Hi all!

Hope someone can help me here.

The official Android documentation says that the re-sizing of graphics for various screen densities should go like this:

XHDPI - 2x
HDPI - 1.5x
MDPI (Baseline) - 1x
LDPI .75x

Now lets say I've created a background images of 2560 x 1504 for my Google Nexus 10 tablet (which is XHDPI).

In my MDPI folder sits a version of this file which is 1280 x 752, this is OK but when I run my app on a Samsung Galaxy Ace phone it uses this file and the screen is only 480 x 320, the phone itself is pretty low spec and it takes ages to load and scale the image , not to mention (I would assume), taking up unnecessary memory on a phone which doesn't have much to begin with.

So it seems a bit ( maybe more than a bit) wasteful. If I just create an image of 480 x 320 and stick that in the MDPI folder, then if I run the app on say a Galaxy Tab 10.1 with it's 1280 x 800 MDPI screen, then the OS would have some major scaling up to do, which I'm sure would give bad results.

So what to do in the this situation?!

Would really welcome comments from anyone on how to go about this. Thanks! :-)
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3932
    
  17

You put different sizes of the image in each of the different size-based folders. For example, you could do:

Default resources: /drawable
Varied Density-based resources: /drawable-xhdpi, /drawable-hdpi, /drawable-ldpi
Medium Density Default resources: /drawable-mdpi
Medium Density Size-based Resources: /drawable-small, /drawable-normal, /drawable-large, /drawable-xlarge

You could be extra-super-duper nice and combine Density and size:
/drawable-small-ldpi, /drawable-small-mdpi, /drawable-small-hdpi, /drawable-small-xhdpi, etc...
but you usually don't have to be that precise or complete.

See: This page, and this one.


Steve
Stephen Bell
Ranch Hand

Joined: May 11, 2013
Posts: 35
Hi Steve

I already have 4 sets of drawables in each of the folders but my question relates to how to resize them.

If I follow Android's official docs, then an image of 2560 x 1600 in my XHDPI folder would be 1280 x 800 in the MDPI folder.

However, a Samsung Galaxy Ace phone picks it's resources up from the MDPI folder and it's screen resolution is only 480 x 320. So the system would have to scale the 1280 x 800 image which takes time and uses resources which are already scarce on this handset.

If I start with a 480 x 320 image in MDPI then (again, following Google's Android Docs), the image in XHDPI would then be 960 x 640 which would then have to be scaled up to run on a Nexus 10 tablet (which gets it's resources from the XHDPI folder) which would produce undesirable visuals. (Not to mention it would have to be scaled up for other MDPI devices with higher res screens such as the Galaxy Tab 10.1).

Hope I'm making sense.

Any advise on how best to resize these images so that they appear nice on as many devices as possible without (using unnecessary resources etc) would really be a great help - thanks!!! :-)
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3932
    
  17

Right, if you read the docs I pointed to, then you realize that you could (should) use more than 4, those for folders you have are related to the pixel density, not the size. So you could add more folders to take care of size.

Example:
You have your Samsung Galaxy Ace, which has a 480x320 pixel screen size. This puts it in the 'normal' category. So you would create a /drawable-normal-mdpi folder and put your 480 x 320 image there. that means you could use the un-sized, density dependent folder (/drawable-ldpi, /drawable-mdpi, /drawable-hdpi, and /drawable-xhdpi) for your larger sized image based on the 1280 x 800 image in the /drawable-mdpi folder. If you don't have a /drawable-xlarge-mdpi folder, then the Galaxy Tab 10.1 would take it from the /drawable-mdpi folder, and it would get the 1280 x 800 version of the image.

Or, you could reverse it, put the 480 x 320 pixel 'normal' sized images in the un-sized folders (/drawable-ldpi, /drawable-mdpi, /drawable-hdpi, and /drawable-xhdpi) and put the larger images based on the the 1280 x 800 mdpi image into /drawable-xlarge-nnnn folders.

Or you could cherry pick and only create a subset of /drawable folders with combination size and density components that cover small-ldpi to xlarge-xhdpi and let Android determine the closest one to the phone.
Stephen Bell
Ranch Hand

Joined: May 11, 2013
Posts: 35
Sorry Steve, I didn't see those links in your original reply.

One of them is the Official Android Doc that I referred to in my post. The other I haven't seen before, so I will have a read through - cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resizing Android Bitmap Resources
 
Similar Threads
Tablet support in general and table specific APIs
size of images in different screens
Best packaging strategy for 'image apps'
Images for multi screen support
How to convert Android App to Samsung Galaxy S2