app/src/main/java/cn/lytcom/camera2kit/Camera2Fragment.java
/**
     * Capture a still picture. This method should be called when we get a response in
     * {@link #mCaptureCallback} from both {@link #lockFocus()}.
     */
Capture a still picture. This method should be called when we get a response in
#mCaptureCallback from both  #lockFocus().
Capture a still picture . This method should be called when we get a response in #mCaptureCallback from both #lockFocus () .
private void captureStillPicture() {
        try {
            removeCaptureMessage();
            final Activity activity = getActivity();
            if (null == activity || null == mCameraDevice) {
                return;
            }
            final CaptureRequest.Builder captureBuilder =
                mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
            captureBuilder.addTarget(mImageReader.getSurface());
            updateFlash(captureBuilder);
            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) {
                    unlockFocus();
                }
            };
            mPreviewSession.stopRepeating();
            mPreviewSession.capture(captureBuilder.build(), CaptureCallback, mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
private void captureStillPicture ( ) { try { removeCaptureMessage ( ) ; final Activity activity = getActivity ( ) ; if ( null == activity || null == mCameraDevice ) { return ; } final CaptureRequest . Builder captureBuilder = mCameraDevice . createCaptureRequest ( CameraDevice . TEMPLATE_STILL_CAPTURE ) ; captureBuilder . addTarget ( mImageReader . getSurface ( ) ) ; updateFlash ( captureBuilder ) ; 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 ) { unlockFocus ( ) ; } } ; mPreviewSession . stopRepeating ( ) ; mPreviewSession . capture ( captureBuilder . build ( ) , CaptureCallback , mBackgroundHandler ) ; } catch ( CameraAccessException e ) { e . printStackTrace ( ) ; } }
Capture a still picture.
Capture a still picture .
// This is the CaptureRequest.Builder that we use to take a picture. // Use the same AE and AF modes as the preview. //            captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, //                CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); //            updateAutoFocus(); // Orientation