保存文件:BitmapFactory.decodeFile返回null即使圖像中存在
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正確顯示。
你關閉了文件輸出流嗎?什麼是「我」設置,爲什麼它有一個單一的字符名稱? – Douglas 2010-08-02 14:53:40
是的,它已關閉。我是一個圖像視圖,它被設置爲空,因爲我不正確地引用它。 – stealthcopter 2010-08-02 16:09:32