Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Bitmap to Drawable in android?

How can I convert a Bitmap image to Drawable ?

like image 605
Farha Ansari Avatar asked Mar 10 '10 09:03

Farha Ansari


People also ask

How do I change a bitmap 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.

How to convert Bitmap to Drawable in Android Studio?

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.

How do I use BitmapDrawable?

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.


1 Answers

Try this it converts a Bitmap type image to Drawable

Drawable d = new BitmapDrawable(getResources(), bitmap); 
like image 166
Manoj Avatar answered Sep 30 '22 09:09

Manoj