java - BitmapFactory.decodeResourse() returns null for shape defined in xml drawable -
java - BitmapFactory.decodeResourse() returns null for shape defined in xml drawable -
i looked through multiple similar questions, although haven't found proper reply on query. have 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 convert bitmap object in order perform operations, bitmapfactory.decoderesource returns null.
bitmap bmp = bitmapfactory.decoderesource(getresources(), r.drawable.shape);
what doing wrong? bitmapfactory.decoderesourse() applicable xml defined drawables?
since want load drawable
, not bitmap
, utilize this:
drawable d = getresources().getdrawable(...);
to turn bitmap
:
public static bitmap drawabletobitmap (drawable drawable) { if (drawable instanceof bitmapdrawable) { homecoming ((bitmapdrawable)drawable).getbitmap(); } bitmap bitmap = bitmap.createbitmap(drawable.getintrinsicwidth(), drawable.getintrinsicheight(), config.argb_8888); canvas canvas = new canvas(bitmap); drawable.setbounds(0, 0, canvas.getwidth(), canvas.getheight()); drawable.draw(canvas); homecoming bitmap; }
taken from: how convert drawable bitmap?
java android android-drawable xml-drawable
Comments
Post a Comment