Java tutorial
//package com.java2s; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; public class Main { public static Bitmap getBitmapFromResource(int resourceId, Resources res, Integer sampleSize) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = sampleSize == null ? 1 : sampleSize; options.outMimeType = "image/jpeg"; options.inDither = false; options.inPurgeable = true; options.inInputShareable = true; options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inTempStorage = new byte[256]; return BitmapFactory.decodeResource(res, resourceId, options); } }