BitmapFactory.decodeResource and drawable* folders

2020-07-05 05:31发布

问题:

I am wondering if decodeResource (Resources res, int id, BitmapFactory.Options opts) takes into account the drawable-ldpi,mdpi,hdpi etc. folders.

I checked the source code, and it doesn't look like that, but I may be missing something.

(Generally, where are the R.drawable. resolved in Android source? I was unable to find it.)

回答1:

Yes it takes it into account. For example if you do :

Resources res = getContext().getResources();
int id = R.drawable.image; 
Bitmap b = BitmapFactory.decodeResource(res, id);

The bitmap will be different if "image" is present in all of the drawables folders. So I think using the overloaded method decodeResource (Resources res, int id, BitmapFactory.Options opts) will work in the same way.