裁剪照片时出现 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 文件资源管理器中,所以我不确定我做错了什么。非常感谢任何建议。
I'm trying to crop a photo to use in a Live Wallpaper but I'm getting a FileNotFoundException when the crop activity tries to save my new cropped image. This is the code I'm using:
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);
The wallpaper.jpg file seems to exist on DDMS file explorer so I'm not sure what I'm doing wrong. Any advice is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
getFilesDir() 返回应用程序的私有目录。相机无法访问您的私人目录。要使相机可以访问壁纸.jpg,请将其放置在某个 publix 文件夹中。例如,就像Alex所说的,它可以是sd卡root。固定代码是:
getFilesDir() return your application's privte directory. Camera can't access your private directory. To make wallpaper.jpg accessible by Camera place it in some publix folder. For example like Alex said it can be sd card root. The fixed code would be:
http://developer.android.com/guide/topics/数据/data-storage.html#filesExternal
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal