Android Utililty Methods Drawable to Bitmap Convert

List of utility methods to do Drawable to Bitmap Convert

Description

The list of methods to do Drawable to Bitmap Convert are organized into topic(s).

Method

BitmapDrawableToBitmap(Drawable drawable)
Drawable To Bitmap
try {
    Bitmap bitmap = Bitmap
            .createBitmap(
                    drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight(),
                    drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                            : Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bitmap);
...
BitmapconvertDrawableToBitmap(Drawable drawable)
convert Drawable To Bitmap
Bitmap bitmap = Bitmap
        .createBitmap(
                drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                        : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
Bitmapdrawable2Bitmap(Drawable drawable)
drawable Bitmap
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
Bitmap bitmap = Bitmap
        .createBitmap(
                width,
                height,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                        : Bitmap.Config.RGB_565);
...
BitmapdrawableToBitmap(Drawable drawable)
drawable To Bitmap
Bitmap bitmap = Bitmap
        .createBitmap(
                drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                        : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
BitmapdrawableToBitmap(Drawable drawable, int width, int height)
drawable To Bitmap
Bitmap bitmap = Bitmap.createBitmap(width, height,
        Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, (int) (height / 2.0), width, height);
drawable.draw(canvas);
return bitmap;
BitmapgetBitmap(Resources resources, int drawableResourceId)
get Bitmap
return BitmapFactory.decodeResource(resources, drawableResourceId);
BitmapDrawablegetBitmapDrawable(Context context, int resId)
get Bitmap Drawable
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
InputStream is = context.getResources().openRawResource(resId);
Bitmap bitmap = BitmapFactory.decodeStream(is, null, opt);
try {
    is.close();
...
Bitmapfrom(Drawable drawable)
from
BitmapDrawable bitDrawable = (BitmapDrawable) drawable;
return bitDrawable.getBitmap();
BitmapdrawableToBitmap(Drawable drawable)
drawable To Bitmap
Bitmap bitmap = Bitmap
        .createBitmap(
                drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                        : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...
BitmapdrawableToBitmap(Drawable drawable)
drawable To Bitmap
Bitmap bitmap = Bitmap
        .createBitmap(
                drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
                        : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
...