使用 ACTION_IMAGE_CAPTURE 从相机拍摄照片后如何跳过或避免“重拍并查看”选项

Posted

技术标签:

【中文标题】使用 ACTION_IMAGE_CAPTURE 从相机拍摄照片后如何跳过或避免“重拍并查看”选项【英文标题】:How to skip or avoid 'retake and review' option after capturing photo from camera using ACTION_IMAGE_CAPTURE 【发布时间】:2016-11-29 14:12:32 【问题描述】:

我想在单击照片时显示图像并希望在我的 ImageView 中设置而无需用户选择是或否......

我已经搜索过它,并且我也非常清楚相机应用程序本身使您能够查看/重新拍摄图像,并且一旦图像被接受,活动就会显示它。但是,我想在不审查/重新参加活动的情况下进行显示.....

我正在尝试这段代码

初始化

  Uri mImageCaptureUri;

点击按钮

  Intent intent      = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    File file        = new File(Environment.getExternalStorageDirectory(),
            "tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg");
    mImageCaptureUri = Uri.fromFile(file);

    try 

        intent.putExtra(MediaStore.AUTHORITY, true);
        intent.putExtra("return-data", true);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
        startActivityForResult(intent, PICK_FROM_CAMERA);
     catch (Exception e) 
        e.printStackTrace();
    

onActivityResult

  @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) 

        Bitmap bitmap = null;


        mPath = mImageCaptureUri.getPath();

        System.out.println("THE PAtH:_" + mPath);

        BitmapFactory.Options o2 = new BitmapFactory.Options();
        bitmap = BitmapFactory.decodeFile(mPath, o2);
        ivSelfie.setImageBitmap(bitmap);

    

When I am Click the Photo Than I am Take this screen to select yes or not......

但是我的要求是不选择review/retake任务,直接在activity显示上设置为ImageView,只需点击设置.....

【问题讨论】:

我没有解决方法,但您可以使用框架布局并仅在您的应用程序中启动相机,而不是使用相机意图。这样更容易。 是的,我知道,但是我要求只使用内置摄像头...... 即使在 WhatsApp 中,在以前的版本中,当他们使用股票相机应用程序时,即使他们在拍摄照片后也有相同的确认选项。 【参考方案1】:

实际上,确认拍摄的照片非常有用。但是,如果你真的不想拥有它,你必须在你的应用程序中使用 SurfaceView 并在此处显示相机流。有一些例子如何做到这一点,例如考虑检查one。

【讨论】:

谢谢@Divers先生...... @Er.Arjunsaini 老实说,不知道在说什么,但似乎无法满足您的要求 谢谢...我也是...拒绝那样做...但我正在努力满足我的要求【参考方案2】:

使用setImageURI()方法,它将从uri中获取位图并为您设置。

是的,它会设置用户按下okcancel 的图像天气,因为您的文件在启动意图时存在于您的给定路径中。

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) 

    if (requestCode == PICK_FROM_CAMERA) 
        // only one line code
        ivSelfie.setImageURI(mImageCaptureUri);
     

【讨论】:

它是否与问题有关 - `当我点击照片时,我会在此屏幕上选择是或否......? 感谢@Sohail Zahid 先生的回答......我也在尝试这个但我想避免审查/重拍的功能............ @Er.Arjunsaini retake/review 属于相机应用程序,您无法控制它们相机应用程序界面仅在cancelOk 上给我们事件结果。 @Sohail Zahid .....谢谢....我也在搜索那个...但是没有得到什么都说你也说过... @Er.Arjunsaini 欢迎您,亲爱的,有些事情超出了我们的控制范围,因此请寻找其他解决方案。快乐编码【参考方案3】:

你无法避开那个屏幕。原因是当您使用新的MediaStore.ACTION_IMAGE_CAPTURE 时,您使用的是不同的相机应用程序来单击图像。显示此屏幕可能是默认功能。根据相机应用程序的不同,此屏幕在不同设备中会有所不同。

因此,要摆脱这种情况,您唯一能做的就是实现自定义相机,而不是使用默认相机应用程序。

【讨论】:

【参考方案4】:

根据默认相机应用,您不能违反该功能。相反,您可以使用 SurfaceView 在您的应用程序中捕获图像。请看看这个answer thread。

也许这个链接会对你有所帮助。

谢谢

【讨论】:

【参考方案5】:

为您的图片意图使用“android.intent.extra.quickCapture”。

// File ImagePickerModule.java#248
cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("android.intent.extra.quickCapture",true);

详情请见https://github.com/react-native-community/react-native-image-picker/issues/647。

【讨论】:

以上是关于使用 ACTION_IMAGE_CAPTURE 从相机拍摄照片后如何跳过或避免“重拍并查看”选项的主要内容,如果未能解决你的问题,请参考以下文章

使用 ACTION_IMAGE_CAPTURE 从相机拍摄照片后如何跳过或避免“重拍并查看”选项

使用 MediaStore.ACTION_IMAGE_CAPTURE 打开前置摄像头 [重复]

在 android 中使用 MediaStore.ACTION_IMAGE_CAPTURE 意图捕获图像

Android MediaStore.ACTION_IMAGE_CAPTURE 和 Intent.ACTION_PICK

如何停止 MediaStore.ACTION_IMAGE_CAPTURE 复制图片

action_image_capture 重新启动应用程序