0

I have a process that does a composite of two images, and it works brilliantly across all my devices *except my galaxy nexus which for reasons that I can't understand mis-reports the dimensions of the art, over-estimating it by about 30%.

I've tried putting the art in both a drawable and a drawable_hdpi folder (not that that should matter) but the image is always pulled at this wrong size. I'm not an expert in DPI, but the thing is that all this is happening prior to anything being drawn to anywhere. I'm simply LOADING the bitmap from the resource and asking what its dimensions are and getting this 30% increased number. It compounds the mystery for me that the image is being blown up! So, it's losing quality in the process as well.

Does anyone have any thoughts on what could possibly be causing this? I only have one ICS device (the Samsung Nexus) so, I'm not sure if this is an ICS issue or a device issue.

I'm getting around it by scaling the art to its original size, but it took me a while to figure out what the heck is going on and I'm curious to know if I'm overlooking something really important in how art is stored and read in ICS or if this is just a bug.

TIA

TZHX
  • 5,291
  • 15
  • 47
  • 56
Yevgeny Simkin
  • 27,946
  • 39
  • 137
  • 236

1 Answers1

4

Android automatically scales resources up (and down) when they are not available at the device's native density (xhdpi for the Galaxy Nexus) docs and more docs

So if you have an image that is only in the mdpi folder at 100x100 the system will automatically scale it up to 150x150 for hdpi and 200x200 for xhdpi. Obviously you are going to lose quality here so you should provide images at multiple densities (commonly hdpi and xhdpi). If you don't want the image to be scaled at all then you can place it in the nodpi folder or the assets folder.

mdpi is the baseline because it was the density of the first device (G1) and is 160dpi

hdpi is 240dpi (1.666 * mdpi)

xhdpi is 320dpi (2 * mdpi)

Now when you are reading the resource via BitmapFactory it will report the dimensions of the image already scaled for you, not the actual resource dimensions. In most cases this is what you want to happen.

smith324
  • 13,020
  • 9
  • 37
  • 58
  • that's an incredibly useful answer! thanks! I wish I could up-vote it twice. I guess the only thing I'm not understanding now is why the heck is the Nexus xhdpi, even as the xyboard is hdpi (the xyboard is MORE resolute than the nexus)... what exactly are they using to determine which device will think of itself as which bucket? – Yevgeny Simkin May 20 '12 at 01:38
  • Its a combination of resolution and density, so the nexus has more pixels per inch then the xyboard. Density is an important measure because it allows buttons to be the same physical (inches under your fingers) size across all screens. The formula is in the second link ` px = dp * (dpi / 160)` but you never really need it. – smith324 May 22 '12 at 01:52