Read Bitmap By Id - Android Graphics

Android examples for Graphics:Bitmap Read

Description

Read Bitmap By Id

Demo Code


//package com.java2s;

import java.io.InputStream;

import android.content.Context;
import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

public class Main {

    public static Bitmap ReadBitmapById(Context context, int resId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;//from   w  w  w  .  j av a2  s.  c  o m
        opt.inInputShareable = true;
       
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, opt);
    }
}

Related Tutorials