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
Android automatically scales resources up (and down) when they are not available at the device’s native density (
xhdpifor the Galaxy Nexus) docs and more docsSo if you have an image that is only in the
mdpifolder at 100×100 the system will automatically scale it up to 150×150 forhdpiand 200×200 forxhdpi. Obviously you are going to lose quality here so you should provide images at multiple densities (commonlyhdpiandxhdpi). If you don’t want the image to be scaled at all then you can place it in thenodpifolder or theassetsfolder.mdpiis the baseline because it was the density of the first device (G1) and is 160dpihdpiis 240dpi (1.666 * mdpi)xhdpiis 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.