How can I convert a Bitmap image to Drawable ?
This example demonstrates how do I convert Drawable to a Bitmap in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.
Having seen a large amount of issues with bitmaps incorrectly scaling when converted to a BitmapDrawable , the general way to convert should be: Drawable d = new BitmapDrawable(getResources(), bitmap); Without the Resources reference , the bitmap may not render properly, even when scaled correctly.
A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a BitmapDrawable from a file path, an input stream, through XML inflation, or from a Bitmap object. Create drawable from a bitmap, setting initial target density based on the display metrics of the resources.
Try this it converts a Bitmap
type image to Drawable
Drawable d = new BitmapDrawable(getResources(), bitmap);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With