Android 如何以流的方式读取图片文件
Android 如何以流的方式读取图片文件
在读取sdcard中的图片文件时,如何以流的方式读取图片文件,请参阅下面的函数:
- public static void ShowImg(String uri, ImageView iv) throws IOException {
- FileInputStream fs = new FileInputStream(uri);
- BufferedInputStream bs = new BufferedInputStream(fs);
- Bitmap btp = BitmapFactory.decodeStream(bs);
- iv.setImageBitmap(btp);
- bs.close();
- fs.close();
- btp = null;
- }
以流的方式读取要比直接以文件的方式读取:Bitmap btp = BitmapFactory.decodeFile(uri); 代码要多很多,
可为什么要用这种方式,系统要提供这样的方法呢?具体原因,我没有深入学习,不过,网上有种说法,以流的方式读取,可能更利于垃圾回收,不知道真假!
评论暂时关闭