我查看了多个类似的问题,虽然我的查询没有找到正确的答案.
我有一个drawable,在shape.xml中定义
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/bg_color" />
</shape>
Run Code Online (Sandbox Code Playgroud)
我想将其转换为Bitmap对象以执行某些操作,但BitmapFactory.decodeResource()返回null.
这就是我这样做的方式:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.shape);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?是BitmapFactory.decodeResource()适用于XML定义可绘制?