get Bitmap From Assert - Android android.graphics

Android examples for android.graphics:Bitmap Create

Description

get Bitmap From Assert

Demo Code

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static Bitmap getBitmapFromAssert(Context thisContext,
            String name) {//from   w  ww . j a  va 2 s . co m
        Bitmap bm = null;
        try {
            AssetManager am = thisContext.getAssets();
            InputStream is = am.open(name);
            bm = BitmapFactory.decodeStream(is);
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return bm;
    }

}

Related Tutorials