decode Resource to Bitmap - Android Graphics

Android examples for Graphics:Bitmap Resource

Description

decode Resource to Bitmap

Demo Code


//package com.java2s;

import java.io.InputStream;
import android.content.Context;
import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class Main {
    @SuppressWarnings("deprecation")
    public static Bitmap decodeResource(Context context, int resourseId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
        opt.inPurgeable = true;/* w w  w .  j a v  a  2 s  . co m*/
        opt.inInputShareable = true; 

        InputStream is = context.getResources().openRawResource(resourseId);

        return BitmapFactory.decodeStream(is, null, opt); 
    }
}

Related Tutorials