get Bitmap From Assets by file name - Android App

Android examples for App:Assets Image

Description

get Bitmap From Assets by file name

Demo Code


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

public class Main {

    public static Bitmap getBitmapFromAssets(Context context,
            String filename) {/*from ww  w .j a  va  2s . c  o m*/
        Bitmap bitmap = null;
        try {
            AssetManager localAssetManager = context.getAssets();
            InputStream localInputStream = localAssetManager.open(filename);
            bitmap = BitmapFactory.decodeStream(localInputStream);
            localInputStream.close();
        } catch (Exception ex) {
        }
        return bitmap;
    }
}

Related Tutorials