камера2 api выход черный изображение

Я использую камеру 2 api, используя этот код

private void createCameraPreviewSession() {
    try {
        SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
        surfaceTexture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        Surface previewSurface = new Surface(surfaceTexture);
        mPreviewCaptureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewCaptureRequestBuilder.addTarget(previewSurface);

        mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader.getSurface()),
                new CameraCaptureSession.StateCallback() {
                    @Override
                    public void onConfigured(CameraCaptureSession session) {

                        if(mCameraDevice == null) {
                            return;
                        }
                        try {

                            mPreviewCaptureRequest = mPreviewCaptureRequestBuilder.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);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

это методы lockfocus, я заметил, что он создает черное изображение с нулевым размером файла после закрытия изображения

if(getPackageManager().hasSystemFeature("android.hardware.camera.autofocus")){
                        photoButton.setEnabled(true);
                        mState = STATE__WAIT_LOCK;
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                                CaptureRequest.CONTROL_AF_TRIGGER_START);
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);

                        mCameraCaptureSession.capture(mPreviewCaptureRequestBuilder.build(),
                                mSessionCaptureCallback, mBackgroundHandler);


    this is my capturing an image

    CaptureRequest.Builder captureStillBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
                captureStillBuilder.addTarget(mImageReader.getSurface());

                if (isAutoFocusSupported())
                    mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                            CaptureRequest.CONTROL_AF_MODE_AUTO);
                else
                    mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                            CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

                int rotation = getWindowManager().getDefaultDisplay().getRotation();
                captureStillBuilder.set(CaptureRequest.JPEG_ORIENTATION,
                        ORIENTATIONS.get(rotation));

                CameraCaptureSession.CaptureCallback captureCallback =
                        new CameraCaptureSession.CaptureCallback() {
                            @Override
                            public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) {
                                super.onCaptureStarted(session, request, timestamp, frameNumber);

                                try {
                                        mImageFile = createImageFile();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }

                            @Override
                            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
                                super.onCaptureCompleted(session, request, result);
                                mCaptureResult = result;
                                unLockFocus();
                            }
                        };

                mCameraCaptureSession.stopRepeating();
                mCameraCaptureSession.capture(
                        captureStillBuilder.build(), captureCallback, null
                );

кто-нибудь испытывает это и как вы исправили эту проблему?

java,android,android-camera2,

0

Ответов: 0

камера2 api выход черный изображение

Я использую камеру 2 api, используя этот код

private void createCameraPreviewSession() {
    try {
        SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
        surfaceTexture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
        Surface previewSurface = new Surface(surfaceTexture);
        mPreviewCaptureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewCaptureRequestBuilder.addTarget(previewSurface);

        mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader.getSurface()),
                new CameraCaptureSession.StateCallback() {
                    @Override
                    public void onConfigured(CameraCaptureSession session) {

                        if(mCameraDevice == null) {
                            return;
                        }
                        try {

                            mPreviewCaptureRequest = mPreviewCaptureRequestBuilder.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);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

это методы lockfocus, я заметил, что он создает черное изображение с нулевым размером файла после закрытия изображения

if(getPackageManager().hasSystemFeature("android.hardware.camera.autofocus")){
                        photoButton.setEnabled(true);
                        mState = STATE__WAIT_LOCK;
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                                CaptureRequest.CONTROL_AF_TRIGGER_START);
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
                        mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);

                        mCameraCaptureSession.capture(mPreviewCaptureRequestBuilder.build(),
                                mSessionCaptureCallback, mBackgroundHandler);


    this is my capturing an image

    CaptureRequest.Builder captureStillBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
                captureStillBuilder.addTarget(mImageReader.getSurface());

                if (isAutoFocusSupported())
                    mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                            CaptureRequest.CONTROL_AF_MODE_AUTO);
                else
                    mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                            CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

                int rotation = getWindowManager().getDefaultDisplay().getRotation();
                captureStillBuilder.set(CaptureRequest.JPEG_ORIENTATION,
                        ORIENTATIONS.get(rotation));

                CameraCaptureSession.CaptureCallback captureCallback =
                        new CameraCaptureSession.CaptureCallback() {
                            @Override
                            public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) {
                                super.onCaptureStarted(session, request, timestamp, frameNumber);

                                try {
                                        mImageFile = createImageFile();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }

                            @Override
                            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
                                super.onCaptureCompleted(session, request, result);
                                mCaptureResult = result;
                                unLockFocus();
                            }
                        };

                mCameraCaptureSession.stopRepeating();
                mCameraCaptureSession.capture(
                        captureStillBuilder.build(), captureCallback, null
                );

кто-нибудь испытывает это и как вы исправили эту проблему?

00Java, Android, андроид-Camera2,
Похожие вопросы
Яндекс.Метрика