Camera2错误的参数传递给了相机服务

Camera2错误的参数传递给了相机服务

本文介绍了Android:Camera2错误的参数传递给了相机服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人做错了吗?我想使用SurfaceView捕获具有预览屏幕的图像.我能够在曲面视图上显示预览.

Can somebody what I have done wrong... I wanted to capture the image which I have a preview screen using SurfaceView. I am able to show the preview on the surface view.

这是我捕获图像的代码

if (mCameraSession == null && mCameraDevice == null) return;

    ImageReader reader = ImageReader.newInstance(mTexturePreviewSize.getWidth(),
                            mTexturePreviewSize.getHeight(),
                            ImageFormat.JPEG, 1);
    reader.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler);

    Surface surface = reader.getSurface();
    try {

        CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        requestBuilder.addTarget(surface);
        mCameraSession.capture(requestBuilder.build(), sessionCaptureListener, null);

下面是我收到的错误消息.

Below is the error message i received.

java.lang.IllegalArgumentException: Bad argument passed to camera service
        at android.hardware.camera2.utils.CameraBinderDecorator.throwOnError(CameraBinderDecorator.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:397)
        at $Proxy2.submitRequestList(Unknown Source)
        at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:617)
        at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:503)
        at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:161)
        at Control.CameraApi21Plus.captureSinglePhoto(CameraApi21Plus.java:171)
        at com.CameraActivity$2.onClick(CameraActivity.java:108)

捕获单个照片功能:

   public void captureSinglePhoto() {

    if (mCameraSession == null && mCameraDevice == null) return;

    ImageReader reader = ImageReader.newInstance(mTexturePreviewSize.getWidth(),
            mTexturePreviewSize.getHeight(),
            ImageFormat.JPEG, 1);
    reader.setOnImageAvailableListener(imageAvailableListener, mBackgroundHandler);

    Surface surface = reader.getSurface();
    try {

        CaptureRequest.Builder requestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        requestBuilder.addTarget(surface);

        mCameraSession.stopRepeating();
        mCameraSession.capture(requestBuilder.build(), sessionCaptureListener, null);

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

private ImageReader.OnImageAvailableListener imageAvailableListener = new ImageReader.OnImageAvailableListener()
{
    @Override
    public void onImageAvailable(ImageReader reader) {
        Image img = reader.acquireLatestImage();
    }
};

private CameraCaptureSession.CaptureCallback sessionCaptureListener = new CameraCaptureSession.CaptureCallback() {
    @Override
    public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
        //super.onCaptureCompleted(session, request, result);
    }
};

推荐答案

您只能捕获到为该会话配置的表面,因此您应该在创建会话之前准备该表面.

You can only capture to a surface that is configured for the session, so you should prepare the surface before the session is created.

在正式文件中:

就像在那儿一样,创建会话时需要准备好表面mImageReader.getSurface()

Just like there, you need to have the surface mImageReader.getSurface() ready when you create the session

           mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
                new CameraCaptureSession.StateCallback() {
                    ...
                }, null);

官方样本:

https://github.com/googlesamples/android-Camera2Basic/tree/master/Application/src/main/java/com/example/android/camera2basic

这篇关于Android:Camera2错误的参数传递给了相机服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 17:34