-1

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
Alex
  • 1,447
  • 7
  • 23
  • 48
  • 1
    I just used your question's title in google: http://stackoverflow.com/questions/8717333/converting-drawable-resource-image-into-bitmap – Lino Aug 01 '16 at 13:01
  • It's not what I asked. I want to convert it to a Bitmap from a string like the one I specified, not just converting a picture – Alex Aug 01 '16 at 14:04

3 Answers3

0
Bitmap bitmap= BitmapFactory.decodeResource(context.getResources(),R.drawable.myphoto);
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
0
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
}
0
    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.

Alex
  • 1,447
  • 7
  • 23
  • 48