Load an image from assets folder

后端 未结 8 1775
天命终不由人
天命终不由人 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:41

    Here you are,

      public Bitmap getBitmapFromAssets(String fileName) {
        AssetManager assetManager = getAssets();
    
        InputStream istr = assetManager.open(fileName);
        Bitmap bitmap = BitmapFactory.decodeStream(istr);
        istr.close();
    
        return bitmap;
    }
    

提交回复
热议问题