Opening a File from assets folder in android

前端 未结 6 984
面向向阳花
面向向阳花 2020-12-01 14:37

I have a .gif file inside the assets folder like this assets/Files/android.gif. when I try to open the file it throws an exception at the second line

AssetM         


        
6条回答
  •  离开以前
    2020-12-01 14:57

    These Lines are working perfectly--

    InputStream assetInStream=null;
    
    try {
        assetInStream=getAssets().open("icon.png");
        Bitmap bit=BitmapFactory.decodeStream(assetInStream);
        img.setImageBitmap(bit);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if(assetInStream!=null)
        assetInStream.close();
    }
    

    If your image is very big then you should scale your image before decoding it into Bitmap. See How to display large image efficiently

提交回复
热议问题