Currently, I'm loading images as follows:

sampleimage= BitmapFactory.decodeResource(context.getResources(), R.drawable.sampleimage);

This automatically chooses the correct image from the drawable-hdpi, drawable-mdpi or drawable-ldpi folders.

How can I load the bitmap using the image name as the string "sampleimage.png"?


1 Answer 1


If you want to access bitmaps by full file name you can store them in assets folder. Then obtain AssetManager from your Activity by calling getAssets() and use AssetManager.open(String fileName) or AssetManager.openFd(...) method.

If you only want to force Android to not get bitmap from mdpi, ldpi and hdpi folders (depending on device parameters) then store your resources in res/drawable folder (without "-*dpi" suffix). You can also provide bitmaps in res/raw folder and then they wouldn't be scaled (what may occure in res/drawable folder).

There is one more difference between assets and res/drawable or res/raw folder. In assets resources can be put in subfolders in your way of organizing thins.

Look for more info at http://developer.android.com/guide/topics/resources/providing-resources.html and http://developer.android.com/reference/android/content/res/AssetManager.html


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .