Skip to content

Instantly share code, notes, and snippets.

@alvareztech
Last active December 15, 2018 06:58
Show Gist options
  • Save alvareztech/6627673 to your computer and use it in GitHub Desktop.
Save alvareztech/6627673 to your computer and use it in GitHub Desktop.
Android: Create Bitmap object from assets, resources, etc.
// From resource
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.image);
// From assets
public static Bitmap getBitmapFromAsset(Context context, String strName) {
AssetManager assetManager = context.getAssets();
InputStream istr;
Bitmap bitmap = null;
try {
istr = assetManager.open(strName);
bitmap = BitmapFactory.decodeStream(istr);
} catch (IOException e) {
return null;
}
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment