-1

The below method returns the Drawable object

public Drawable getIcon() {
        return icon;
    }

but when i put this method where Drawable is required, it gives me error saying "Required type int provided Drawable." like here in second argument of decodeResource method.

Bitmap b = BitmapFactory.decodeResource(mContext.getResources(), appInformations.get(position).getIcon());
  • Consider using [this](https://stackoverflow.com/a/10600736/9701793), since you want to convert a `Drawable` object to `Bitmap` – rahat Jan 16 '21 at 05:05

1 Answers1

0

The 2nd parameter of the decodeResource function is resource id (for example R.drawable.abc) and not of drawable type. If you have the drawable in resource folder, you can give resource id of that drawable directly. Or modify the getIcon function to return resource id (of type R.drawable.abc which is of type int and not Drawable).

Antonio
  • 1,264
  • 7
  • 12
  • you are right, but I have resources in databases and this is the scenario I need to do things. so how can it be done without changin the data type of getIcon – Nooraib Khurshid Jan 16 '21 at 07:33
  • then you have to use method to create bitmap from Drawable – Antonio Jan 16 '21 at 07:42
  • "android.graphics.drawable.AdaptiveIconDrawable@40bc0d0" this is the string i am recieving and i want to set it as an image, when i do using BitmapDrawable.createFromPath() or Drawable.createFromPath() it gives me transparent image – Nooraib Khurshid Jan 16 '21 at 07:51