如何将Levellist Drawabrable转换为位图或图标



我得到了这个异常

java.lang.ClassCastException:
android.graphics.drawable.LevelListDrawable cannot be cast to
android.graphics.drawable.BitmapDrawable

在此行中获得异常

Drawable d= getResources().getDrawable(R.drawable.kb, null);
d.setLevel(3);   
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

您可以直接从 Drawable文件夹中获取位图,如下面的代码:

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

最新更新