我查看了多个类似的问题,尽管我还没有找到我的问题的正确答案。
我有一个可绘制的,在 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>
我想将它转换为 Bitmap 对象以执行一些操作,但BitmapFactory.decodeResource()
返回 null。
这就是我的做法:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.shape);
我究竟做错了什么?BitmapFactory.decodeResource()
适用于 xml 定义的可绘制对象吗?