get Bitmap from Resource - Android App

Android examples for App:Resource

Description

get Bitmap from Resource

Demo Code


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

public class Main {
    private static Options mOpt = new Options();

    public static Bitmap getBitmap(Context context, int resId) {
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, mOpt);
    }// w w  w  .j av  a2 s . c o  m

    public static Bitmap getBitmap(Context context, int resId, Options opt) {
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, opt);
    }

    public static Bitmap getBitmap(String filePath) {
        return BitmapFactory.decodeFile(filePath, mOpt);
    }

    public static Bitmap getBitmap(String filePath, Options opt) {
        return BitmapFactory.decodeFile(filePath, opt);
    }
}

Related Tutorials