Load an image from assets folder

后端 未结 8 1774
天命终不由人
天命终不由人 2020-11-28 07:06

I am trying to load an image from the asset folder and then set it to an ImageView. I know it\'s much better if I use the R.id.* for t

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 07:20

    public static Bitmap getImageFromAssetsFile(Context mContext, String fileName) {
            Bitmap image = null;
            AssetManager am = mContext.getResources().getAssets();
            try {
                InputStream is = am.open(fileName);
                image = BitmapFactory.decodeStream(is);
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return image;
        }
    

提交回复
热议问题