如何捕获图像并将其存储在本机 Android 相机中 [英] How to capture an image and store it with the native Android Camera
问题描述
我在捕捉图像并从本机相机应用程序存储图像时遇到问题.这是我的一些代码示例.
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屋!