当前位置:首页 > 读取Bitmap对象的几种方法

读取Bitmap对象的几种方法

点击次数:1813  更新日期:2013-07-04

几种读取Bitmap的方法。

1.以文件流的方式,假设在sdcard下有 test.png图片

FileInputStream fis = new FileInputStream("/sdcard/test.png");

Bitmap bitmap = BitmapFactory.decodeStream(fis);

2. 以R文件的方式,假设 res/drawable下有 test.jpg文件

Bitmap bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.test);

3.以ResourceStream的方式,但不用到R文件。

Bitmap.bitmap=BitmapFactory.decodeStream(getClass().getResourceAsStream(“/res/drawable/test.png”)