中易网

android,如何读取资源文件里的图片到bitmap里

答案:3  悬赏:50  
解决时间 2021-01-16 21:56
  • 提问者网友:酱爆肉
  • 2021-01-16 07:16
android,如何读取资源文件里的图片到bitmap里
最佳答案
  • 二级知识专家网友:人间朝暮
  • 2021-01-16 07:52
方式:以R文件的方式
路径:假设 res/drawable下有 test.jpg文件
Bitmap bitsrc=BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.test)
三种方式:

现总结以下几种读取Bitmap的方法:
以文件流的方式,假设在sdcard下有 test.png图片
FileInputStream fis = new FileInputStream("/sdcard/test.png");
Bitmap bitmap  = BitmapFactory.decodeStream(fis);
以R文件的方式,假设 res/drawable下有 test.jpg文件
Bitmap  bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.test);

以ResourceStream的方式,但不用到R文件
Bitmap.bitsrc=BitmapFactory.decodeStream(getClass.getResourceAsStream(“/res/drawable/test.png”)
全部回答
  • 1楼网友:渊鱼
  • 2021-01-16 09:08
刚才用那个同学的回答,确实对了,哈哈,谢谢你的提问啊
  • 2楼网友:过活
  • 2021-01-16 08:58
以R文件的方式,假设 res/drawable下有 test.jpg文件
Bitmapbitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.test);
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息