在我将TEMPLATE从PREVIEW更改为MANUAL之后,我将Bad参数传递给了相机服务。 Camera2Api

时间:2016-11-07 16:22:06

标签: android camera illegalargumentexception android-camera2

我需要设置iso。为了做到这一点,我需要更改模板。我做到了

有我的代码

private void createCameraPreviewSession() {
    try {
        SurfaceTexture texture = textureView.getSurfaceTexture();
        texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
        final Surface surface = new Surface(texture);

        if (cameraDevice != null) {


---->>>    //                mPreviewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL);
---->>>           mPreviewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);


        }

        mPreviewRequestBuilder.addTarget(surface);

        cameraDevice.createCaptureSession(Arrays.asList(surface, imageReader.getSurface()), new CameraCaptureSession.StateCallback() {
            @Override
            public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                // The camera is already closed
                if (null == cameraDevice) {
                    return;
                }

                captureSession = cameraCaptureSession;
                try {

                    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
                    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
                    mPreviewRequest = mPreviewRequestBuilder.build();

                    if (!UtilClass.isNull(cameraDevice)) {
                        captureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
                    }

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

            @Override
            public void onConfigureFailed(
                    @NonNull CameraCaptureSession cameraCaptureSession) {
            }
        }, null);

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

最终我收到了这样的错误

FATAL EXCEPTION: CameraBackground
    Process: com.fittingroom.newtimezone, PID: 31752
    java.lang.IllegalArgumentException: Bad argument passed to camera service
     at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBi nderDecorator.java:114)
     at android.hardware.camera2.utils.CameraBinderDecorator$CameraBinderDecoratorListener.onAfterInvocation(CameraBinderDecorator.java:73)
     at android.hardware.camera2.utils.Decorator.invoke(Decorator.java:81)
     at java.lang.reflect.Proxy.invoke(Proxy.java:393)
     at $Proxy2.createDefaultRequest(Unknown Source)
     at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureRequest(CameraDeviceImpl.java:628)
     at com.fittingroom.newtimezone.view.ActivityCamera.createCameraPreviewSession(ActivityCamera.java:556)
     at com.fittingroom.newtimezone.view.ActivityCamera.access$1000(ActivityCamera.java:72)
     at com.fittingroom.newtimezone.view.ActivityCamera$2.onOpened(ActivityCamera.java:144)
     at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:134)
     at android.os.Handler.handleCallback(Handler.java:739)
     at android.os.Handler.dispatchMessage(Handler.java:95)
     at android.os.Looper.loop(Looper.java:158)
     at android.os.HandlerThread.run(HandlerThread.java:61)

这可能是什么原因?

提前致谢!

4 Android:Camera2 Bad参数传递给摄像头服务2 0我收到java.lang.RuntimeException:无法连接到android中的摄像头服务? 1 android:无法连接到targetSdkVersion上的摄像头服务更改2 0旋转后相机未连接到相机维修 0传递参数到相机活动2 1将Apache Service Startup类型更改为Manual 2

0 个答案:

没有答案