Example usage for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION

List of usage examples for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION

Introduction

In this page you can find the example usage for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION.

Prototype

Key JPEG_ORIENTATION

To view the source code for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION.

Click Source Link

Document

The orientation for a JPEG image.

The clockwise rotation angle in degrees, relative to the orientation to the camera, that the JPEG picture needs to be rotated by, to be viewed upright.

Camera devices may either encode this value into the JPEG EXIF header, or rotate the image data to match this orientation.

Usage

From source file:freed.cam.apis.camera2.modules.PictureModuleApi2.java

/**
 * Capture a still picture. This method should be called when we get a response in
 *
 *//*from   w w w.j  a v  a 2s.c  om*/
protected void captureStillPicture() {
    Log.d(TAG, "StartStillCapture");

    // Use the same AE and AF modes as the preview.
    try {
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, cameraHolder.get(CaptureRequest.CONTROL_AF_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, cameraHolder.get(CaptureRequest.CONTROL_AE_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.FLASH_MODE, cameraHolder.get(CaptureRequest.FLASH_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.COLOR_CORRECTION_MODE,
                cameraHolder.get(CaptureRequest.COLOR_CORRECTION_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.COLOR_CORRECTION_TRANSFORM,
                cameraHolder.get(CaptureRequest.COLOR_CORRECTION_TRANSFORM));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.COLOR_CORRECTION_GAINS,
                cameraHolder.get(CaptureRequest.COLOR_CORRECTION_GAINS));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.TONEMAP_CURVE, cameraHolder.get(CaptureRequest.TONEMAP_CURVE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        if (Build.VERSION.SDK_INT >= VERSION_CODES.M)
            captureBuilder.set(CaptureRequest.TONEMAP_GAMMA, cameraHolder.get(CaptureRequest.TONEMAP_GAMMA));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }

    try {
        int awb = cameraHolder.get(CaptureRequest.CONTROL_AWB_MODE);
        captureBuilder.set(CaptureRequest.CONTROL_AWB_MODE, awb);
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.EDGE_MODE, cameraHolder.get(CaptureRequest.EDGE_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.HOT_PIXEL_MODE, cameraHolder.get(CaptureRequest.HOT_PIXEL_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.NOISE_REDUCTION_MODE,
                cameraHolder.get(CaptureRequest.NOISE_REDUCTION_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION,
                cameraHolder.get(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        long val = 0;
        if (!parameterHandler.ManualIso.GetStringValue().equals(KEYS.AUTO))
            val = (long) (AbstractManualShutter.getMilliSecondStringFromShutterString(
                    parameterHandler.ManualShutter.getStringValues()[parameterHandler.ManualShutter.GetValue()])
                    * 1000f);
        else
            val = cameraHolder.get(CaptureRequest.SENSOR_EXPOSURE_TIME);
        Log.d(TAG, "Set ExposureTime for Capture to:" + val);
        captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, val);
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY,
                cameraHolder.get(CaptureRequest.SENSOR_SENSITIVITY));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE,
                cameraHolder.get(CaptureRequest.CONTROL_EFFECT_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.CONTROL_SCENE_MODE,
                cameraHolder.get(CaptureRequest.CONTROL_SCENE_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE,
                cameraHolder.get(CaptureRequest.LENS_FOCUS_DISTANCE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
                cameraUiWrapper.getActivityInterface().getOrientation());
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE,
                cameraHolder.get(CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        captureBuilder.set(CaptureRequest.SCALER_CROP_REGION,
                cameraHolder.get(CaptureRequest.SCALER_CROP_REGION));
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }
    try {
        if (appSettingsManager.getApiString(AppSettingsManager.SETTING_LOCATION).equals(KEYS.ON))
            captureBuilder.set(CaptureRequest.JPEG_GPS_LOCATION,
                    cameraUiWrapper.getActivityInterface().getLocationHandler().getCurrentLocation());
    } catch (NullPointerException ex) {
        ex.printStackTrace();
    }

    prepareCaptureBuilder(captureBuilder);
    imagecount = 0;
    //mDngResult = null;
    if (parameterHandler.Burst != null && parameterHandler.Burst.GetValue() > 0) {
        initBurstCapture(captureBuilder, CaptureCallback);
    } else {
        //cameraHolder.CaptureSessionH.StopRepeatingCaptureSession();
        captureBuilder.setTag(mRequestCounter.getAndIncrement());
        captureBuilder.addTarget(mImageReader.getSurface());
        if (cameraHolder.get(CaptureRequest.SENSOR_EXPOSURE_TIME) != null
                && cameraHolder.get(CaptureRequest.SENSOR_EXPOSURE_TIME) > 500000 * 1000)
            cameraHolder.CaptureSessionH.StopRepeatingCaptureSession();
        ImageHolder imageHolder = new ImageHolder();
        resultQueue.put((int) captureBuilder.build().getTag(), imageHolder);
        changeCaptureState(CaptureStates.image_capture_start);
        cameraHolder.CaptureSessionH.StartImageCapture(captureBuilder, CaptureCallback, mBackgroundHandler);
    }
}

From source file:com.example.testcamera.Camera2BasicFragmentEasy.java

private void takePicture() {
    try {//ww w.  j  a  v  a2  s  .com
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

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

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                showToast("Saved: " + mFile);
                try {
                    mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null,
                            mBackgroundHandler);
                } catch (CameraAccessException e) {
                    e.printStackTrace();
                }
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);

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

From source file:com.manufacton.cordova.MyCameraManager.java

/**
 * Creates a new {@link CameraCaptureSession} for camera preview.
 *///from w  ww . j  a v a 2s . co m
private void createCameraPreviewSession() {
    try {

        // We set up a CaptureRequest.Builder with the output Surface.
        mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewRequestBuilder.addTarget(mImageReader.getSurface());
        Log.d(TAG, "OPENING CAPTURE SESSION");
        // Here, we create a CameraCaptureSession for camera preview.
        mCameraDevice.createCaptureSession(Arrays.asList(mImageReader.getSurface()),
                new CameraCaptureSession.StateCallback() {

                    @Override
                    public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                        // The camera is already closed
                        if (null == mCameraDevice) {
                            return;
                        }
                        Log.d(TAG, "IN onConfigured");
                        // When the session is ready, we start displaying the preview.
                        mCaptureSession = cameraCaptureSession;
                        try {
                            // Auto focus should be continuous for camera preview.
                            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
                            int displayRotation = activity.getWindowManager().getDefaultDisplay().getRotation();
                            mPreviewRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION,
                                    ORIENTATIONS.get(displayRotation));
                            // Flash is automatically enabled when necessary.
                            // setAutoFlash(mPreviewRequestBuilder);

                            // Finally, we start displaying the camera preview.
                            mPreviewRequest = mPreviewRequestBuilder.build();
                            mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                                    mBackgroundHandler);
                        } catch (CameraAccessException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
                        Log.d(TAG, "onConfigured FAILED");
                    }
                }, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.testcamera.Camera2BasicFragmentGoogle.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *///w  w  w .  ja  v  a 2s . com
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                    TotalCaptureResult result) {
                Toast.makeText(getActivity(), "Saved: " + mFile, Toast.LENGTH_SHORT).show();
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.android.learnmore.Camera2BasicFragment.java

private void captureStillPicture() {
    try {//from   www . j a v  a  2s .  c om
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));

        CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), captureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.tzutalin.vision.demo.Camera2BasicFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *///w w  w  .  java2  s .c  o  m
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                Log.d(TAG, mFile.toString());
                unlockFocus();

                Intent intent = null;
                if (mAction == VisionAction.ObjDetect) {
                    intent = new Intent(getActivity(), ObjectDetectActivity.class);
                } else if (mAction == VisionAction.SceneRecognition) {
                    intent = new Intent(getActivity(), SceneRecognitionActivity.class);
                }
                if (intent != null) {
                    Bundle bundle = new Bundle();
                    bundle.putString(Camera2BasicFragment.KEY_IMGPATH, mFile.toString());
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), captureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:cliq.com.cliqgram.fragments.CameraFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *//*from  w  ww.jav  a 2  s .  com*/
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

        // check to turn on/off flash mode
        captureBuilder.set(CaptureRequest.FLASH_MODE,
                flashOn ? CaptureResult.FLASH_MODE_SINGLE : CaptureResult.FLASH_MODE_OFF);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                showToast("Saved: " + mFile);
                Log.d(TAG, "Saved file: " + mFile.toString());
                unlockFocus();

                startImageDisplayActivity(mFile.getName());

            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.rockacode.ocr.ui.camera.CameraFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *//*from   ww  w  . j  a  v  a  2 s  .  c om*/
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                showToast("Saved: " + mFile);
                startImageDetails(imageFilePath);
                Log.d(TAG, mFile.toString());
                Log.d(TAG, imageFilePath);
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.janicduplessis.myapplication.CameraFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *///from w  w w  .  j av a 2 s.  co m
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                // showToast("Saved: " + mFile);
                // Log.d(TAG, mFile.toString());
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:info.staticfree.mqtt_camera.fragment.CameraFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #captureCallback} from both {@link #lockFocus()}.
 *///ww w .j  a va 2s  .com
private void captureStillPicture() {
    try {
        Activity activity = getActivity();
        if (null == activity || null == cameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        CaptureRequest.Builder captureBuilder = cameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(imageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        if (autoFocus) {
            captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        } else {
            captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
        }
        setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {

                if (autoFocus) {
                    unlockFocus();
                }

                if (showPreview) {
                    textureView.setVisibility(View.VISIBLE);
                    restartPreview();
                } else {
                    state = STATE_PREVIEW;
                    textureView.setVisibility(View.INVISIBLE);
                }
            }
        };

        captureSession.stopRepeating();
        captureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Error capturing image", e);
    }
}