Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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"?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.