如何将输入配置传递给Camera 2 Android [英] How to pass input configuration to camera 2 android

查看:124
本文介绍了如何将输入配置传递给Camera 2 Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个android相机应用程序,我想在拍摄照片之前传递捕获大小以配置相机.

I am developing an android camera application, and I wanted to pass in the capture size to configure the camera before taking a picture.

这是我的代码:

try {
    mCaptureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    mCaptureRequestBuilder.addTarget(previewSurface);

    InputConfiguration inputConfiguration = new InputConfiguration(1920, 1080, ImageFormat.JPEG); //error here.

    cameraDevice.createReprocessableCaptureSession(inputConfiguration, Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback() {
            @Override
            public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                try {
                    cameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(), null, handler);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
                Toast.makeText(getApplicationContext(), "Camera Preview Failed!!", Toast.LENGTH_SHORT).show();
            }
    }, null);
}

因此,我正在尝试将输入配置传递给此处的相机. 我的问题是在InputConfiguration行上出现错误. 这是我的错误:

So, I am trying to pass an input configuration to the camera here. My problem is I'm getting an error on the InputConfiguration line. This is my error:

java.lang.IllegalArgumentException: input format 256 is not valid

我尝试了很多不同的ImageFormat,例如JPEG,UNKNOWN,NV21等.没用 可以帮助我解决此错误,并且如果我的方法在与相机交互时出错,也可以告诉我.

I tried this with a lot of different ImageFormats like JPEG, UNKNOWN, NV21 and others. It's not working. Help me resolve this error and also if my approach is wrong in interacting with the camera do tell me.

推荐答案

此处描述了另一种可悲的情况:

Another sad case is described here: https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#REPROCESS_MAX_CAPTURE_STALL

检查相机是否支持后处理,否则根本不会通过输入格式无效",因为不允许进行后处理.

Check that your camera supports reprocessing or you would not pass through "input format is not valid" at all as no input would be allowed for reprocessing.

此外,如果缺少此键值,则可能表示无法进行Yuv重新处理:

Also the absence of this key value can signal that Yuv reprocessing is not available: https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING

这篇关于如何将输入配置传递给Camera 2 Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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