Android openRawResource() not working for a drawable

﹥>﹥吖頭↗ 提交于 2019-11-30 17:53:44

@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!

Broatian

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!