android.hardware.camera2.CameraCaptureSession Java Examples

The following examples show how to use android.hardware.camera2.CameraCaptureSession. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QrCameraC2.java    From flutter_qr_mobile_vision with MIT License 6 votes vote down vote up
private void startPreview() {
    CameraCaptureSession.CaptureCallback listener = new CameraCaptureSession.CaptureCallback() {
        @Override
        public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
            super.onCaptureCompleted(session, request, result);
        }
    };

    if (cameraDevice == null) return;

    try {
        previewSession.setRepeatingRequest(previewBuilder.build(), listener, null);
    } catch (java.lang.Exception e) {
        e.printStackTrace();
    }
}
 
Example #2
Source File: BlockingSessionCallback.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
@Override
public void onSurfacePrepared(CameraCaptureSession session, Surface surface) {
    mSessionFuture.setSession(session);
    if (mProxy != null) {
        mProxy.onSurfacePrepared(session, surface);
    }
    // Surface prepared doesn't cause a session state change, so don't trigger the
    // state change listener
    synchronized (mPreparedSurfaces) {
        List<Surface> preparedSurfaces = mPreparedSurfaces.get(session);
        if (preparedSurfaces == null) {
            preparedSurfaces = new ArrayList<Surface>();
        }
        preparedSurfaces.add(surface);
        mPreparedSurfaces.put(session, preparedSurfaces);
        mPreparedSurfaces.notifyAll();
    }
}
 
Example #3
Source File: CaptureCallback.java    From android-robocar with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onCaptureFailed(@NonNull CameraCaptureSession session,
                            @NonNull CaptureRequest request,
                            @NonNull CaptureFailure failure) {
  super.onCaptureFailed(session, request, failure);
  this.session = null;
  switch (failure.getReason()) {
    case CaptureFailure.REASON_ERROR:
      Timber.e("Capture failed: REASON_ERROR");
      break;
    case CaptureFailure.REASON_FLUSHED:
      Timber.e("Capture failed: REASON_FLUSHED");
      break;
    default:
      Timber.e("Capture failed: UNKNOWN");
      break;
  }
}
 
Example #4
Source File: FocusManager.java    From FastBarcodeScanner with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param cameraCaptureSession Session
 * @param callbackHandler the handler on which the listener should be invoked, or
 * {@code null} to use the current thread's {@link android.os.Looper
 * looper}.
 * @param listener Listener receiving callbacks
 * @param lockFocus l
 */
public void start(CameraCaptureSession cameraCaptureSession, boolean lockFocus, Handler callbackHandler, FocusListener listener)
{
    mCameraCaptureSession = cameraCaptureSession;
    // When the session is ready, we start displaying the preview.
    try {
        Log.i(TAG, "StartFocusing");
        mStateMachine = new FocusingStateMachine(cameraCaptureSession, lockFocus, callbackHandler, listener);
        mStateMachine.start(mPreviewSurface);
    } catch (Exception e) {
        if (cameraCaptureSession != null) {
            stop();//cameraCaptureSession.stopRepeating();
        }
        //mPreviewImageReader.setOnImageAvailableListener(null, null);
        mPreviewImageReader = null;
        e.printStackTrace();
    }
}
 
Example #5
Source File: Camera2Source.java    From Camera2Vision with Apache License 2.0 6 votes vote down vote up
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
    if(request.getTag() == ("FOCUS_TAG")) {
        //The focus trigger is complete!
        //Resume repeating request, clear AF trigger.
        mAutoFocusCallback.onAutoFocus(true);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, null);
        mPreviewRequestBuilder.setTag("");
        mPreviewRequest = mPreviewRequestBuilder.build();
        try {
            mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
        } catch(CameraAccessException ex) {
            Log.d(TAG, "AUTO FOCUS FAILURE: "+ex);
        }
    } else {
        process(result);
    }
}
 
Example #6
Source File: Camera2Source.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
    if (request.getTag() == ("FOCUS_TAG")) {
        //The focus trigger is complete!
        //Resume repeating request, clear AF trigger.
        mAutoFocusCallback.onAutoFocus(true);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, null);
        mPreviewRequestBuilder.setTag("");
        mPreviewRequest = mPreviewRequestBuilder.build();
        try {
            mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
        } catch (CameraAccessException ex) {
            Log.d(TAG, "AUTO FOCUS FAILURE: " + ex);
        }
    } else {
        process(result);
    }
}
 
Example #7
Source File: CallbackProxies.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureQueueEmpty(CameraCaptureSession session) {
    final long ident = Binder.clearCallingIdentity();
    try {
        mExecutor.execute(() -> mCallback.onCaptureQueueEmpty(session));
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example #8
Source File: CallbackProxies.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onClosed(CameraCaptureSession session) {
    final long ident = Binder.clearCallingIdentity();
    try {
        mExecutor.execute(() -> mCallback.onClosed(session));
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example #9
Source File: VideoCaptureCamera2.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigured(CameraCaptureSession cameraCaptureSession) {
    Log.d(TAG, "CrPreviewSessionListener.onConfigured");
    mPreviewSession = cameraCaptureSession;
    try {
        // This line triggers the preview. A |listener| is registered to receive the actual
        // capture result details. A CrImageReaderListener will be triggered every time a
        // downloaded image is ready. Since |handler| is null, we'll work on the current
        // Thread Looper.
        mPreviewSession.setRepeatingRequest(
                mPreviewRequest, new CameraCaptureSession.CaptureCallback() {
                    @Override
                    public void onCaptureCompleted(CameraCaptureSession session,
                            CaptureRequest request, TotalCaptureResult result) {
                        mLastExposureTimeNs =
                                result.get(CaptureResult.SENSOR_EXPOSURE_TIME);
                    }
                }, null);

    } catch (CameraAccessException | SecurityException | IllegalStateException
            | IllegalArgumentException ex) {
        Log.e(TAG, "setRepeatingRequest: ", ex);
        return;
    }
    // Now wait for trigger on CrPreviewReaderListener.onImageAvailable();
    nativeOnStarted(mNativeVideoCaptureDeviceAndroid);
    changeCameraStateAndNotify(CameraState.STARTED);
}
 
Example #10
Source File: CameraHandler.java    From sample-tensorflow-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                               @NonNull CaptureRequest request,
                               @NonNull TotalCaptureResult result) {
    session.close();
    mCaptureSession = null;
    Log.d(TAG, "CaptureSession closed");
}
 
Example #11
Source File: CameraDeviceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public CaptureRequest.Builder createCaptureRequest(int templateType,
        Set<String> physicalCameraIdSet)
        throws CameraAccessException {
    synchronized(mInterfaceLock) {
        checkIfCameraClosedOrInError();

        for (String physicalId : physicalCameraIdSet) {
            if (physicalId == getId()) {
                throw new IllegalStateException("Physical id matches the logical id!");
            }
        }

        CameraMetadataNative templatedRequest = null;

        templatedRequest = mRemoteDevice.createDefaultRequest(templateType);

        // If app target SDK is older than O, or it's not a still capture template, enableZsl
        // must be false in the default request.
        if (mAppTargetSdkVersion < Build.VERSION_CODES.O ||
                templateType != TEMPLATE_STILL_CAPTURE) {
            overrideEnableZsl(templatedRequest, false);
        }

        CaptureRequest.Builder builder = new CaptureRequest.Builder(
                templatedRequest, /*reprocess*/false, CameraCaptureSession.SESSION_ID_NONE,
                getId(), physicalCameraIdSet);

        return builder;
    }
}
 
Example #12
Source File: CameraHandler.java    From androidthings-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
    // The camera is already closed
    if (mCameraDevice == null) {
        return;
    }
    // When the session is ready, we start capture.
    mCaptureSession = cameraCaptureSession;
    triggerImageCapture();
}
 
Example #13
Source File: Camera2.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
/**
 * Captures a still picture.
 */
void captureStillPicture() {
    try {
        CaptureRequest.Builder captureRequestBuilder = mCamera.createCaptureRequest(
                CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureRequestBuilder.addTarget(mImageReader.getSurface());
        captureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                mCaptureRequestBuilder.get(CaptureRequest.CONTROL_AF_MODE));
        updateFlashLightState();
        // Calculate JPEG orientation.
        @SuppressWarnings("ConstantConditions")
        int sensorOrientation = mCameraCharacteristics.get(
                CameraCharacteristics.SENSOR_ORIENTATION);
        captureRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION,
                (sensorOrientation +
                        mDisplayOrientation * (mConfig.getCurrentFacing() == Constants.CAMERA_FACING_FRONT ? 1 : -1) +
                        360) % 360);
        // Stop preview and capture a still picture.
        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureRequestBuilder.build(),
                new CameraCaptureSession.CaptureCallback() {
                    @Override
                    public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                                   @NonNull CaptureRequest request,
                                                   @NonNull TotalCaptureResult result) {
                        unlockFocus();
                    }
                }, null);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Cannot capture a still picture.", e);
    }
}
 
Example #14
Source File: CameraFragment.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 */
private void captureStillPicture() {
    Log.d(TAG, "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);

        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION,
                getJpegOrientation(mCharacteristics, mOrientation));

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

            @Override
            public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                                           TotalCaptureResult result) {
                showToast("Saved Picture");
                //unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #15
Source File: CameraDeviceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void createReprocessableCaptureSessionByConfigurations(InputConfiguration inputConfig,
        List<OutputConfiguration> outputs,
        android.hardware.camera2.CameraCaptureSession.StateCallback callback, Handler handler)
                throws CameraAccessException {
    if (DEBUG) {
        Log.d(TAG, "createReprocessableCaptureSessionWithConfigurations");
    }

    if (inputConfig == null) {
        throw new IllegalArgumentException("inputConfig cannot be null when creating a " +
                "reprocessable capture session");
    }

    if (outputs == null) {
        throw new IllegalArgumentException("Output configurations cannot be null when " +
                "creating a reprocessable capture session");
    }

    // OutputConfiguration objects aren't immutable, make a copy before using.
    List<OutputConfiguration> currentOutputs = new ArrayList<OutputConfiguration>();
    for (OutputConfiguration output : outputs) {
        currentOutputs.add(new OutputConfiguration(output));
    }
    createCaptureSessionInternal(inputConfig, currentOutputs,
            callback, checkAndWrapHandler(handler),
            /*operatingMode*/ICameraDeviceUser.NORMAL_MODE, /*sessionParams*/ null);
}
 
Example #16
Source File: Camera2Source.java    From Camera2Vision with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureFailed(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull CaptureFailure failure) {
    if(request.getTag() == "FOCUS_TAG") {
        Log.d(TAG, "Manual AF failure: "+failure);
        mAutoFocusCallback.onAutoFocus(false);
    }
}
 
Example #17
Source File: CameraDeviceImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void createCustomCaptureSession(InputConfiguration inputConfig,
        List<OutputConfiguration> outputs,
        int operatingMode,
        android.hardware.camera2.CameraCaptureSession.StateCallback callback,
        Handler handler) throws CameraAccessException {
    List<OutputConfiguration> currentOutputs = new ArrayList<OutputConfiguration>();
    for (OutputConfiguration output : outputs) {
        currentOutputs.add(new OutputConfiguration(output));
    }
    createCaptureSessionInternal(inputConfig, currentOutputs, callback,
            checkAndWrapHandler(handler), operatingMode, /*sessionParams*/ null);
}
 
Example #18
Source File: DoorbellCamera.java    From androidthings-cameraCar with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureCompleted(CameraCaptureSession session,
                               CaptureRequest request,
                               TotalCaptureResult result) {
    if (session != null) {
        session.close();
        mCaptureSession = null;
        Log.d(TAG, "CaptureSession closed");
    }
}
 
Example #19
Source File: AndroidCameraCaptureSessionProxy.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureSequenceCompleted(CameraCaptureSession session, int sequenceId,
                                       long frameNumber)
{
    mCallback.onCaptureSequenceCompleted(AndroidCameraCaptureSessionProxy.this,
            sequenceId, frameNumber);
}
 
Example #20
Source File: Camera2Manager.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void captureStillPicture() {
    try {
        if (null == mCameraDevice) {
            return;
        }
        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);
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getPhotoOrientation(cameraConfigProvider.getSensorPosition()));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                           @NonNull CaptureRequest request,
                                           @NonNull TotalCaptureResult result) {
                Log.d(TAG, "onCaptureCompleted: ");
            }
        };

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

    } catch (CameraAccessException e) {
        Log.e(TAG, "Error during capturing picture");
    }
}
 
Example #21
Source File: CameraHandler.java    From sample-tensorflow-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
    // The camera is already closed
    if (mCameraDevice == null) {
        return;
    }
    // When the session is ready, we start capture.
    mCaptureSession = cameraCaptureSession;
    triggerImageCapture();
}
 
Example #22
Source File: AutoStrategy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);

    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #23
Source File: CameraPluginActivity.java    From unity-android-native-camera with MIT License 5 votes vote down vote up
@Override
public void onConfigured(CameraCaptureSession session) {
    CameraPluginActivity.this._captureSession = session;
    try {
        session.setRepeatingRequest(createCaptureRequest(), null, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #24
Source File: Camera2Manager.java    From sandriosCamera with MIT License 5 votes vote down vote up
private void captureStillPicture() {
    try {
        if (null == cameraDevice) {
            return;
        }
        final CaptureRequest.Builder captureBuilder =
                cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(imageReader.getSurface());

        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getPhotoOrientation(configurationProvider.getSensorPosition()));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                           @NonNull CaptureRequest request,
                                           @NonNull TotalCaptureResult result) {
                Log.d(TAG, "onCaptureCompleted: ");
            }
        };

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

    } catch (CameraAccessException e) {
        Log.e(TAG, "Error during capturing picture");
    }
}
 
Example #25
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 5 votes vote down vote up
private void startPreview(CameraCaptureSession session) {
    mCameraCaptureSession = session;
    mCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    HandlerThread backgroundThread = new HandlerThread("CameraPreview");
    backgroundThread.start();
    Handler backgroundHandler = new Handler(backgroundThread. getLooper());
    try {
        mCameraCaptureSession
                .setRepeatingRequest(mCaptureRequestBuilder.build(), null, backgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #26
Source File: CloseStrategy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,CaptureRequest.CONTROL_AE_MODE_OFF);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: BlockingSessionCallback.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Wait until the designated surface is prepared by the camera capture session.
 *
 * @param session the input {@link CameraCaptureSession} to wait for
 * @param surface the input {@link Surface} to wait for
 * @param timeoutMs how many milliseconds to wait for
 *
 * @throws TimeoutRuntimeException if waiting for more than {@long timeoutMs}
 */
public void waitForSurfacePrepared(
        CameraCaptureSession session, Surface surface, long timeoutMs) {
    synchronized (mPreparedSurfaces) {
        List<Surface> preparedSurfaces = mPreparedSurfaces.get(session);
        if (preparedSurfaces != null && preparedSurfaces.contains(surface)) {
            return;
        }
        try {
            long waitTimeRemaining = timeoutMs;
            while (waitTimeRemaining > 0) {
                long waitStartTime = SystemClock.elapsedRealtime();
                mPreparedSurfaces.wait(timeoutMs);
                long waitTime = SystemClock.elapsedRealtime() - waitStartTime;
                waitTimeRemaining -= waitTime;
                preparedSurfaces = mPreparedSurfaces.get(session);
                if (waitTimeRemaining >= 0 && preparedSurfaces != null &&
                        preparedSurfaces.contains(surface)) {
                    return;
                }
            }
            throw new TimeoutRuntimeException(
                    "Unable to get Surface prepared in " + timeoutMs + "ms");
        } catch (InterruptedException ie) {
            throw new AssertionError();
        }
    }
}
 
Example #28
Source File: Camera2Manager.java    From sandriosCamera with MIT License 5 votes vote down vote up
private void updatePreview(CameraCaptureSession cameraCaptureSession) {
    if (null == cameraDevice) {
        return;
    }
    captureSession = cameraCaptureSession;
    previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
    previewRequest = previewRequestBuilder.build();

    try {
        captureSession.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler);
    } catch (Exception e) {
        Log.e(TAG, "Error updating preview: ", e);
    }
    setFlashModeAndBuildPreviewRequest(configurationProvider.getFlashMode());
}
 
Example #29
Source File: Camera2Source.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 */
private void captureStillPicture() {
    try {
        if (null == mCameraDevice) {
            return;
        }
        if (mShutterCallback != null) {
            mShutterCallback.onShutter();
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReaderStill.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, mFocusMode);
        if (mFlashSupported) {
            captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode);
        }

        // Orientation
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(mDisplayOrientation));

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

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

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #30
Source File: CameraHandler.java    From androidthings-imageclassifier with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                               @NonNull CaptureRequest request,
                               @NonNull TotalCaptureResult result) {
    session.close();
    mCaptureSession = null;
    Log.d(TAG, "CaptureSession closed");
}