android get Bitmap or sound from assets

前端 未结 5 1225
陌清茗
陌清茗 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:16

    Use this code its working

    try {
        InputStream bitmap=getAssets().open("icon.png");
        Bitmap bit=BitmapFactory.decodeStream(bitmap);
        img.setImageBitmap(bit);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    

    Update

    While decoding Bitmap we more often meet with memory overflow exception if Image size is very big. So reading article How to display Image efficiently will help you.

提交回复
热议问题