在将其保存到应用程序之前检索捕获的图像

发布于 2024-12-10 20:06:10 字数 55 浏览 0 评论 0原文

作为 Android 新手,我想知道如何检索从相机捕获的图像(我的应用程序通过意图调用该图像)。

Being new to Android, I want to know how we can retrieve the image captured from the camera (which is being called by my application through intents).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我很坚强 2024-12-17 20:06:10

请尝试这个

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 );

Please try this

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 );
撧情箌佬 2024-12-17 20:06:10

桑迪的答案是正确的,但我想添加更多内容,我试图在他的答案中编辑但无法发布 您可以在 onActivityResult() 方法中检查在上面指定的路径处拍摄的新图像

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 ); 

,也不要忘记添加 if() 条件来检查 resultCode 是否正确。像这样,

if (requestCode == 101 && resultCode == Activity.RESULT_OK) { 
  //get Image back from the path like BitmapFactory.decodeFile(path);            
} 

The answer from Sandy is right but I would like to add more, that I tried to edit in his answer but couldn't so posting this

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 ); 

You can check the New Image Taken at the Path specified above in onActivityResult() method also Don't Forget to put if() condition to check the resultCode is Ok or not. like this,

if (requestCode == 101 && resultCode == Activity.RESULT_OK) { 
  //get Image back from the path like BitmapFactory.decodeFile(path);            
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文