Android openRawResource() not working for a drawable

后端 未结 3 399
终归单人心
终归单人心 2021-01-04 08:46

I\'m trying to create an input stream by doing this

InputStream is = (InputStream) getResources().openRawResource(R.drawable.image1);

but I

相关标签:
3条回答
  • 2021-01-04 09:28

    @Broatian I don't currently have a res/raw folder. I found an alternative solution: is = context.getResources().openRawResource(+ R.drawable.image1); The + shows additional folders. Thanks for the help!

    0 讨论(0)
  • 2021-01-04 09:28

    It is because They are expecting a raw type resource and you are passing a drawable type one. make a raw folder in the res folder and then put your image in the raw folder.

    0 讨论(0)
  • 2021-01-04 09:48

    If you want to open your png with this method then you have to put it in the res/raw folder. Then you'll be able to access the png using R.raw.image1.

    Another alternative is to keep it in the drawable folder and then convert the drawable to a InputStream. See How to read drawable bits as InputStream

    I assume you know how to get the drawable otherwise look at the Resources documentation.

    0 讨论(0)
提交回复
热议问题