Android 读取Assets中图片

394 阅读1分钟

 private final static AssetManager mAsset = MyApplication.getContext().getAssets();

/**
 * 从Assets中读取图片
 */

public static Bitmap getImageFromAssetsFile(String fileName) {
    Bitmap bitmap = null;
    try {
        InputStream is = mAsset.open(fileName);
        BitmapFactory.Options options = new BitmapFactory.Options();
        bitmap = BitmapFactory.decodeStream(is, null, options);
        is.close();
    } catch (IOException e) {
        Log.e(TAG, "getImageFromAssetsFile: Could not get assets ", e);
    }
    return bitmap;
}