Android Drawable to Bitmap Convert getMutableBitmap(Drawable drawable)

Here you can find the source of getMutableBitmap(Drawable drawable)

Description

get Mutable Bitmap

License

Open Source License

Declaration

public static Bitmap getMutableBitmap(Drawable drawable) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.graphics.Bitmap;
import android.graphics.Canvas;

import android.graphics.drawable.Drawable;

public class Main {
    public static Bitmap getMutableBitmap(Drawable drawable) {

        if (drawable.getIntrinsicHeight() > 0
                && drawable.getIntrinsicWidth() > 0) {
            Bitmap bitmap = Bitmap.createBitmap(
                    drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight(), Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);/*from  w  ww  . j  av a  2 s.  c  o m*/

            return bitmap;
        }

        return null;
    }
}

Related

  1. drawableToBitmap(Drawable drawable)
  2. drawableToBitmap(Drawable drawable)
  3. convertToBitmap(final Drawable drawable)
  4. drawableToBitmap(Drawable drawable)
  5. drawableToBitmap(Drawable drawable)