How do I convert in Bitmap a droawable resource that I have in form of String as it follows
android.resource://com.example.myapp/drawable/name_picture
How do I convert in Bitmap a droawable resource that I have in form of String as it follows
android.resource://com.example.myapp/drawable/name_picture
Bitmap bitmap= BitmapFactory.decodeResource(context.getResources(),R.drawable.myphoto);
Try the following(there maybe typos):
String path = "android.resource://com.example.myapp/drawable/name_picture";
String[] splitByPath = path.split("drawable/");
if(splitByPath!=null && splitByPath.length >1){
int varId = getResources().getIdentifier(splitByPath[1], "drawable", getPackageName());
Bitmap bmp = BitmapFactory.decodeResource(getResources(),varId);
}else{
//Improper path
}
Uri uriString = Uri.parse("android.resource://com.example.myapp/drawable/name_picture
");
String lastPathIcon = uriString.getLastPathSegment();
int drawableResource = getApplicationContext().getResources()
.getIdentifier("drawable/" + lastPathIcon, null, getApplicationContext().getPackageName());
largeIcon = BitmapFactory.decodeResource(getResources(), drawableResource);
Here the solution that worked for me.