保存文件:
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 正确显示。