错误:无法创建捕获会话

时间:2016-05-05 20:56:10

标签: java android

我使用下面的代码来捕获图像:

mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader.getSurface()), new CameraCaptureSession.StateCallback(){
            @Override
            public void onConfigured(CameraCaptureSession session) {
                if(mCameraDevice == null){
                    return;
                }
                try{
                    mPreviewCaptureRequest = mPreviewCaptureRequestBuider.build();
                    mCameraCaptureSession = session;
                    mCameraCaptureSession.setRepeatingRequest(
                            mPreviewCaptureRequest,
                            mSessionCaptureCallback,
                            mBackgroundHandler
                    );
                }catch(CameraAccessException e){
                    e.printStackTrace();
                }
            }

            @Override
            public void onConfigureFailed(CameraCaptureSession session) {
                Toast.makeText(getApplicationContext(), "create camera session failed!", Toast.LENGTH_SHORT).show();
            }
        }, null);
  

错误:无法创建捕获会话

在设置相机中。我有:

Size largestImageSize = Collections.max(
                    Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
                    new Comparator<Size>() {
    @Override
    public int compare(Size lhs, Size rhs) {
         return Long.signum(lhs.getWidth() * lhs.getHeight() - rhs.getWidth() * rhs.getHeight());
    }
}
);
mImageReader = ImageReader.newInstance(largestImageSize.getWidth(), largestImageSize.getHeight(), ImageFormat.JPEG, 1);
mImageReader.setOnImageAvailableListener(mOnImageAvailableListener, mBackgroundHandler);

权限:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera2.full" />

我认为问题在于从mImageReader获得表面。但是,我不知道该怎么做!

1 个答案:

答案 0 :(得分:0)

您是否在清单文件上设置了以下内容?

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />