It’s possible to load an image from resources passing to R.drawable a String?
I’m trying this:
public static Bitmap LoadBitmap(Context context, String filename)
{
Bitmap image;
image = BitmapFactory.decodeResource(context.getResources(), R.drawable.filename);
return image;
}
Throws the following error:
filename cannot be resolved or is not a field
I’m trying to create the field in the R file creatic a constant but throws the following line:
R.java was modified manually! Reverting to generated version!
I’ll appreciate your help or suggestions. Thanks
Resources can be accessed as raw data: use AssetManager.open(..). Just pass the filename of wanted bitmap (e.g. “drawable/myimage.png”).
Then you can use BitmapFactory.decodeStream(..) to create a Bitmap from the data stream.
Update: