Android Drawable to Bitmap Convert getBitmapDrawable(Context context, int resId)

Here you can find the source of getBitmapDrawable(Context context, int resId)

Description

get Bitmap Drawable

Declaration

public static BitmapDrawable getBitmapDrawable(Context context,
            int resId) 

Method Source Code

//package com.java2s;
import java.io.IOException;
import java.io.InputStream;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;

public class Main {
    public static BitmapDrawable getBitmapDrawable(Context context,
            int resId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;/* w w w. j  a va2  s  . c o m*/
        opt.inInputShareable = true;

        InputStream is = context.getResources().openRawResource(resId);
        Bitmap bitmap = BitmapFactory.decodeStream(is, null, opt);

        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return new BitmapDrawable(context.getResources(), bitmap);

    }
}

Related

  1. convertDrawableToBitmap(Drawable drawable)
  2. drawable2Bitmap(Drawable drawable)
  3. drawableToBitmap(Drawable drawable)
  4. drawableToBitmap(Drawable drawable, int width, int height)
  5. getBitmap(Resources resources, int drawableResourceId)
  6. from(Drawable drawable)
  7. drawableToBitmap(Drawable drawable)
  8. drawableToBitmap(Drawable drawable)
  9. drawableToBitmap(Drawable drawable)