public static Bitmap drawableToBitmap(@NonNull final Drawable drawable) {
        Condition.INSTANCE.ensureNotNull(drawable, "The drawable may not be null");

        if (drawable instanceof BitmapDrawable) {
            BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

            if (bitmapDrawable.getBitmap() != null) {
                return bitmapDrawable.getBitmap();
            }
        }

        Bitmap bitmap;

        if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
            bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        } else {
            bitmap =
                    Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                            Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    }
public static Bitmap drawableToBitmap ( @ NonNull final Drawable drawable ) { Condition . INSTANCE . ensureNotNull ( drawable , "The drawable may not be null" ) ; if ( drawable instanceof BitmapDrawable ) { BitmapDrawable bitmapDrawable = ( BitmapDrawable ) drawable ; if ( bitmapDrawable . getBitmap ( ) != null ) { return bitmapDrawable . getBitmap ( ) ; } } Bitmap bitmap ; if ( drawable . getIntrinsicWidth ( ) <= 0 || drawable . getIntrinsicHeight ( ) <= 0 ) { bitmap = Bitmap . createBitmap ( 1 , 1 , Bitmap . Config . ARGB_8888 ) ; } else { bitmap = Bitmap . createBitmap ( drawable . getIntrinsicWidth ( ) , drawable . getIntrinsicHeight ( ) , Bitmap . Config . ARGB_8888 ) ; } Canvas canvas = new Canvas ( bitmap ) ; drawable . setBounds ( 0 , 0 , canvas . getWidth ( ) , canvas . getHeight ( ) ) ; drawable . draw ( canvas ) ; return bitmap ; }
Creates and returns a bitmap from a specific drawable.

@param drawable
The drawable, which should be converted, as an instance of the class {@link
Drawable}. The drawable may not be null
@return The bitmap, which has been created, as an instance of the class {@link Bitmap}