How to pass input configuration to camera 2 android

一世执手 提交于 2020-06-13 09:27:06

问题


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

This is my code:

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

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

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.


回答1:


You are working with TEMPLATE_PREVIEW, which does not support ImageFormat.JPEG.

Camera2 mandates that preview supports YUV 420, like this:

InputConfiguration inputConfiguration = new InputConfiguration(1920, 1080, ImageFormat.YUV_420_888);



回答2:


Input configurations are only used reprocessing use cases, where you have an application-level circular buffer of captured partially processed frames.

When the user hits the shutter button, you send one of the captured frames back to the camera device for final processing. The input configuration is for selecting the size and format of this path back into the camera.

For simple capture applications, you only care about the output configurations.




回答3:


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.

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



来源:https://stackoverflow.com/questions/52695544/how-to-pass-input-configuration-to-camera-2-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!