I have created multiple bitmaps – one for each folder (mdpi, hdpi, ldpi). Can someone show me some code or point me to the appropriate method that will allow me to detect which resource Android decided to load.
Thanks,
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is available in the bitmap itself — http://developer.android.com/reference/android/graphics/Bitmap.html#getDensity()
If you are loading this through the higher level Resources.getDrawable() API, you won’t have a Bitmap but just an abstract Drawable. If you can guarantee the resource will always be a bitmap (not a nine patch or other such thing), you can cast this to a BitmapDrawable and get the Bitmap from that.
If you are doing this for production code, I would be a little uncomfortable with this since generally an app should either let the framework take care of density, or take care of it all itself (by for example putting the bitmaps in drawable-nodpi). If you are playing games with bitmaps base on loaded density, you may shoot yourself in the foot. Or you may be fine, since I don’t really know what you are doing. 🙂