我得到了这个异常
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);