相关疑难解决方法(0)

BitmapFactory.decodeResource()为xml drawable中定义的形状返回null

我查看了多个类似的问题,虽然我的查询没有找到正确的答案.

我有一个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定义可绘制?

android xml-drawable android-drawable

37
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

android-drawable ×1

xml-drawable ×1