Last active
January 13, 2020 15:31
-
-
Save alphamu/6265084 to your computer and use it in GitHub Desktop.
Code on how to get a bitmap from a Drawable and how to resize that bitmap and return a Drawable. This could prove to be useful if you want to manually resize a drawable or if you want to simply get a bitmap of a drawable. Note: If using Compound Drawables you can simply call `setBounds` on the drawable and set it using the `setCompoundDrawable` …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Drawable resize(Resources r, Drawable image, int newSize) { | |
Bitmap b = ((BitmapDrawable)image).getBitmap(); | |
Bitmap bitmapResized = Bitmap.createScaledBitmap(b, newSize, newSize, false); | |
BitmapDrawable drawableBmp = new BitmapDrawable(r, bitmapResized); | |
return drawableBmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will lead to ClassCastException on Android 8, 9 & 10.
please read comments of answer : stackoverflow.com/a/3036187/3947321