刚接触Android,我想知道如何检索从相机中捕获的图像(我的应用程序通过意图调用它)。
答案 0 :(得分:2)
请试试这个
String path = "File path";
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 );
答案 1 :(得分:1)
answer from Sandy是正确的,但我想添加更多内容,我试图在他的回答中进行编辑,但不能这样发布
String path = "File path";
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, 101 );
您可以在onActivityResult()
方法中查看上面指定的路径中拍摄的新图像,也不要忘记放置if() condition to check the resultCode is Ok or not
。像这样,
if (requestCode == 101 && resultCode == Activity.RESULT_OK) {
//get Image back from the path like BitmapFactory.decodeFile(path);
}