如何使用原生 Android 相机捕获图像并将其存储 [英] How to capture an image and store it with the native Android Camera

查看:18
本文介绍了如何使用原生 Android 相机捕获图像并将其存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在捕获图像并将其从本机相机应用程序存储时遇到问题.这是我的一些代码示例.

I am having a problem capturing an image and storing it from the native camera app. Here is a sample of some of my code.

_path = Environment.getExternalStorageDirectory() + "make_machine_example.jpg";
File file = new File( _path );
Uri outputFileUri = Uri.fromFile( file );

Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );

startActivityForResult( intent, 0 );

拍摄完照片并返回到原始活动后,当我通过 Android DDMS 文件资源管理器导航到我的 sd 卡时,图片不存在.有人知道为什么没有保存吗?

After the picture has been taken and I'm returned back to my original Activity, When I navigate to my sd card via Android DDMS File Explorer the picture is not there. Anyone know why this is not being saved?

推荐答案

你有没有检查过 Environment.getExternalStorageDirectory() 的输出是什么,因为如果它不包含文件尾分隔符 (/) 那么你的图像将结束在不驻留在 SD 卡上的目录中,例如:

Have you checked what the output of Environment.getExternalStorageDirectory() is, because if it does not contain a trailing file seperator (/) then your image will end up in a directory that does not reside on the SDcard such as:

 /mnt/sdcardmake_machine_example.jpg

当你真正想要的是:

 /mnt/sdcard/make_machine_example.jpg

试试这个代码:

 _path = Environment.getExternalStorageDirectory() + File.separator +  "make_machine_example.jpg";

这篇关于如何使用原生 Android 相机捕获图像并将其存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆