Android How to - Convert Bitmap to Drawable








Question

We would like to know how to convert Bitmap to Drawable.

Answer

We can create a BitmapDrawable directly from Bitmap. And the BitmapDrawable is implemented the Drawable interface.

//  w  w w  .ja v a2  s.c o m
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
public class Main {
    public static Drawable bitmapToDrawable(Bitmap bitmap) {
      
    return new BitmapDrawable(bitmap);
    
    }
}