【发布时间】:2010-08-02 14:51:06
【问题描述】:
保存文件:
FileOutputStream fo = null;
try {
fo = this.openFileOutput("test.png", Context.MODE_WORLD_READABLE);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bitmap.compress(CompressFormat.PNG, 100, fo)
加载文件:
String fname = this.getFilesDir().getAbsolutePath()+"/test.png";
Bitmap bMap = BitmapFactory.decodeFile(fname);
i.setImageBitmap(bMap);
最后一行给出了空指针异常,为什么BitmapFactory.decodeFile返回null?我可以验证文件是否正确保存,因为我可以使用 adb 拉取它并看到 png 正确显示。
【问题讨论】:
-
你关闭文件输出流了吗? “i”设置为什么,为什么它只有一个字符名称?
-
是的,它已经关闭了。 i 是一个图像视图,它被设置为 null,因为我错误地引用了它。
标签: android bitmap imageview fileoutputstream