Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.IOException;
import java.io.InputStream;

import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import android.support.v4.app.FragmentActivity;

public class Main {
    public static Bitmap getBitmapFromAsset(FragmentActivity fragmentActivity, String strName) {
        try {
            AssetManager assetManager = fragmentActivity.getAssets();

            InputStream inStream = null;
            try {
                inStream = assetManager.open(strName);
            } catch (IOException e) {
                e.printStackTrace();
            }

            Bitmap bitmap = BitmapFactory.decodeStream(inStream);
            return bitmap;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}