Here you can find the source of getBitmapDrawable(Context context, int resId)
public static BitmapDrawable getBitmapDrawable(Context context, int resId)
//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); } }