Load a bitmap by its resource Id using the given context - Android Graphics

Android examples for Graphics:Bitmap Resource

Description

Load a bitmap by its resource Id using the given context

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;

public class Main {
    /** Load a bitmap by its resId using the given context */
    public static Bitmap loadBitmap(Context context, int resId) {
        return ((BitmapDrawable) context.getResources()//
                .getDrawable(resId))//
                .getBitmap();/*from ww w.j a  va 2 s  .  c o  m*/
    }
}

Related Tutorials