get Bitmap From Asset by name - Android App

Android examples for App:Assets Image

Description

get Bitmap From Asset by name

Demo Code


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

public class Main {
    public static Bitmap getBitmapFromAsset(Context context, String strName) {
        AssetManager assetManager = context.getAssets();

        InputStream istr;/*from w w  w  . j  av  a 2  s  .  c om*/
        Bitmap bitmap = null;
        try {
            istr = assetManager.open(strName);
            bitmap = BitmapFactory.decodeStream(istr);
        } catch (IOException e) {
            return null;
        }

        return bitmap;
    }
}

Related Tutorials