• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Resizing Android Bitmap Resources

 
Ranch Hand
Posts: 55
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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! :-)
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Stephen Bell
Ranch Hand
Posts: 55
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 55
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic