load Bitmap From Resource - Android Graphics

Android examples for Graphics:Bitmap Resource

Description

load Bitmap From Resource

Demo Code


//package com.java2s;

import android.content.Context;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.util.Log;

public class Main {
    private final static String TAG = "AndroidUtil";

    public static Bitmap loadBitmapFromResource(Context context, int id) {
        try {//from   w  ww  .j av a2 s .c o m
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 3;

            return BitmapFactory.decodeResource(context.getResources(), id,
                    options);
        } catch (Exception ex) {
            Log.e(TAG, String.format(
                    "Loading bitmap from resource with id '%s' failed. ",
                    ex));
        }

        return null;
    }
}

Related Tutorials