Camera2 CameraDevice.TEMPLATE_MANUAL

1.1k Views Asked by At

I want to capture pictures through Camera2 API, and I need to control the exposure time. But when I set CameraDevice.TEMPLATE_MANUAL or just set the exposure time, I get black picture. When I cancel the setting, I can get the right picture again.

The following is my setting code.

// if the phone's level is full or other which can control mannually
mCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CONTROL_AE_MODE_OFF);
mCaptureRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, exposureValue);
mCaptureRequestBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, isoValue);
mCaptureRequestBuilder.set(CaptureRequest.SENSOR_FRAME_DURATION,valueFrame);

//exposureValue and isoValue and valueFrame is valid.

        mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader.getSurface()),
                new CameraCaptureSession.StateCallback() {
                    @Override
                    public void onConfigured(CameraCaptureSession session) {
                        Log.e(TAG, "onConfigured: startPreview");
                        mPreviewCaptureSession = session;
                        try {
                            mPreviewCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(),
                                    null, mBackgroundHandler); 
                        } catch (CameraAccessException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onConfigureFailed(CameraCaptureSession session) {
                        Log.e(TAG, "onConfigureFailed: startPreview");

                    }
                }, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

After setting like above, when I capture a picture or save the preview frame, I can just get a black picture. But when I cancel the manual setting, I can save the picture.

I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.

0

There are 0 best solutions below