android get Bitmap or sound from assets

前端 未结 5 1218
陌清茗
陌清茗 2020-12-08 06:34

I need to get Bitmap and sound from assets. I try to do like this:

BitmapFactory.decodeFile(\"file:///android_asset/Files/Numbers/l1.png\");
<
5条回答
  •  死守一世寂寞
    2020-12-08 07:33

    Kotlin way, with auto close of the input stream. You have to handle exceptions on your own.

    private fun getBitmapFromAsset(context: Context, path: String): Bitmap =
            context.assets.open(path).use { BitmapFactory.decodeStream(it) }
    

提交回复
热议问题