2010-06-01 74 views
0

我試圖裁剪照片以在動態壁紙中使用,但當作物活動嘗試保存我的新裁剪圖像時出現FileNotFoundException。這是我正在使用的代碼:修剪照片時發生FileNotFoundException

File file = new File(getFilesDir(), "wallpaper.jpg"); 

Intent intent = new Intent("com.android.camera.action.CROP"); 
intent.setData(uri); 

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics); 

intent.putExtra("outputX", metrics.widthPixels * 2); 
intent.putExtra("outputY", metrics.heightPixels); 
intent.putExtra("aspectX", metrics.widthPixels * 2); 
intent.putExtra("aspectY", metrics.heightPixels); 
intent.putExtra("scale", true); 
intent.putExtra("noFaceDetection", true); 
intent.putExtra("output", Uri.parse("file:/" + file.getAbsolutePath())); 

startActivityForResult(intent, REQUEST_CROP_IMAGE); 

wallpaper.jpg文件似乎存在於DDMS文件資源管理器,所以我不知道我在做什麼錯了。任何意見是極大的讚賞。

回答

0

getFilesDir()返回您的應用程序的privte目錄。相機無法訪問您的私人目錄。爲了使相機能夠訪問wallpaper.jpg,將它放置在某個publix文件夾中。比如像Alex說的那樣可以是SD卡根。固定代碼將爲:

File file = new File(Environment.getExternalStorageDirectory(), "wallpaper.jpg"); 
0

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

如果您使用API​​ 7級或更低, 使用getExternalStorageDirectory(),以 打開代表 外部存儲的根文件。然後 你應該寫你的數據在以下 目錄:

/安卓/數據//文件/ 的是你的Java風格 包的名稱,如 「com.example.android.app」。如果 用戶的設備正在運行API級別8 或更高版本,並且他們卸載了您的 應用程序,則該目錄和所有 的內容將被刪除。