Convert between Bitmap and Drawable

Drawable to Bitmap

It is easy to convert between Drawable and Bitmap in Android.

Above works for jpg, png type drawables, but it does work for xml type of drawable (I guess because xml file has no specific “width”, “height” information).

In this case, you can use following util method.

 Above is cited from How to convert a Drawable to a Bitmap? answered by André.

Bitmap to Drawable

Resize Bitmap


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.




Sponsored Links

2 responses

Leave a Reply

Your email address will not be published.