0

The following code causes ClassCastException on Android 8, 9 & 10. But not on Android 5, 6 & 7.

Bitmap bitmap = ((BitmapDrawable) aDrawable).getBitmap();

compileSdkVersion 29
buildToolsVersion '29.0.2'

minSdkVersion 21
targetSdkVersion 29
Ashraf Alshahawy
  • 1,139
  • 1
  • 14
  • 38
  • 1
    so what? It means that aDrawable is not BitmapDrawable on new sdks. You havent said where it comes from, so it hard to say what really happens. Check it real type with a debugger or in error message. – Leonidos Jan 13 '20 at 13:46
  • 1
    please read comments of answer : https://stackoverflow.com/a/3036187/3947321 – Rujul Gandhi Jan 13 '20 at 13:49
  • BitmapDrawable is derived from Drawable in Android 29. – Ashraf Alshahawy Jan 13 '20 at 13:50
  • https://stackoverflow.com/questions/40417469/unable-to-convert-vector-drawable-to-bitmap-drawable-in-android – Kirguduck Jan 13 '20 at 13:58
  • @RujulGandhi Thank you. I need to change the Drawable (Apps icons) to a BitmapDrawable so I can resize it and show it in a GridView. Is there a method to resize a Drawable as Bitmap.createScaledBitmap(Bitmap)? or How to convert a Drawable to a Bitmap? – Ashraf Alshahawy Jan 13 '20 at 14:20

0 Answers0