Android Asset Read getImgFromAsserts(Context con, String filename)

Here you can find the source of getImgFromAsserts(Context con, String filename)

Description

get Img From Asserts

Declaration

public static Drawable getImgFromAsserts(Context con, String filename) 

Method Source Code

//package com.java2s;
import java.io.IOException;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import android.widget.Toast;

public class Main {
    public static Drawable getImgFromAsserts(Context con, String filename) {

        try {//w  w  w  . ja  va  2s  .com
            return new BitmapDrawable(BitmapFactory.decodeStream(con
                    .getAssets().open(filename)));
        } catch (IOException e) {
            Toast.makeText(con, e.toString(), Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getFileFromAssets(Context context, String file)
  2. listAssetFiles(Context context, String path)
  3. getfromAssets(Context ctx, String file_name)
  4. assetAsByteArray(Resources res, String path)