Last active
December 15, 2018 06:58
-
-
Save alvareztech/6627673 to your computer and use it in GitHub Desktop.
Android: Create Bitmap object from assets, resources, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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