Ho esaminato più domande simili, anche se non ho trovato risposta adeguata sulla mia query.BitmapFactory.decodeResource() restituisce null per la forma definita in xml drawable
Ho un disegnabile, definito 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>
voglio convertirlo in oggetto bitmap per eseguire alcune operazioni, ma BitmapFactory.decodeResource()
restituisce null.
Ecco come lo sto facendo:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.shape);
Che cosa sto facendo di sbagliato? BitmapFactory.decodeResource()
applicabile per i drawable definiti xml?
Mi chiedo come questo può funzionare ... Dal momento che il drawable è una forma definita in XML, 'getIntrinsicWidth()' e 'getIntrinsicHeight()' restituisce sempre -1 e il won bitmap essere creato O sto ricevendo qualcosa di sbagliato? –
Questo genera 'IllegalArgumentException: width e height devono essere> 0' –
Ciò significa che il tuo drawable non ha una dimensione valida. –