在Bitmap Android中转换可绘制图片

时间:2016-08-01 12:54:50

标签: android bitmap type-conversion android-drawable android-bitmap

如何在Bitmap中转换我所拥有的可转换资源,如下所示

android.resource://com.example.myapp/drawable/name_picture

3 个答案:

答案 0 :(得分:0)

Bitmap bitmap= BitmapFactory.decodeResource(context.getResources(),R.drawable.myphoto);

答案 1 :(得分: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
}

答案 2 :(得分: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);

这是适用于我的解决方案。