get Image From Asset File - Android App

Android examples for App:Assets Image

Description

get Image From Asset File

Demo Code


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

public class Main {
    public static Bitmap getImageFromAssetFile(Context context,
            String fileName) {//from  ww  w .  j  ava 2 s  . c o m
        Bitmap image = null;
        try {
            AssetManager am = context.getAssets();
            InputStream is = am.open(fileName);
            image = BitmapFactory.decodeStream(is);
            is.close();
        } catch (Exception e) {
            Log.d("AssertUtil", e.getMessage());
        }
        return image;
    }
}

Related Tutorials