I looked through multiple similar questions, although I haven't found a proper answer to my issue.
I have a drawable, defined in 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>
I want to convert it to Bitmap object in order to perform some operations, but BitmapFactory.decodeResource()
returns null.
This is how I'm doing it:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.shape);
What am I doing wrong? Is BitmapFactory.decodeResource()
applicable for xml defined drawables?
getIntrinsicWidth()
andgetIntrinsicHeight()
will always return -1 and the bitmap won't be created. Or am I getting something wrong? – Piscary