Java Code Examples for android.hardware.camera2.CaptureRequest

The following are top voted examples for showing how to use android.hardware.camera2.CaptureRequest. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: opencv-documentscanner-android   File: Camera2BasicFragment.java   View source code 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 2
Project: Android-Code-Demos   File: Camera2BasicFragment.java   View source code 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 3
Project: 361Camera   File: Camera2Fragment.java   View source code 6 votes vote down vote up
/**
 * Called after a RAW/JPEG capture has completed; resets the AF trigger state for the
 * pre-capture sequence.
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void finishedCaptureLocked() {
    try {
        // Reset the auto-focus trigger in case AF didn't run quickly enough.
        if (!mNoAFRun) {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);

            mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback,
                    mBackgroundHandler);

            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 4
Project: PXLSRT   File: Camera2.java   View source code 6 votes vote down vote up
/**
 * Unlocks the auto-focus and restart camera preview. This is supposed to be called after
 * capturing a still picture.
 */
void unlockFocus() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
        updateAutoFocus();
        updateFlash();
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
        mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
                null);
        mCaptureCallback.setState(PictureCaptureCallback.STATE_PREVIEW);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to restart camera preview.", e);
    }
}
 
Example 5
Project: android-robocar   File: CaptureCallback.java   View source code 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 6
Project: OkayCamera-Android   File: Camera2RawFragment.java   View source code 6 votes vote down vote up
/**
 * Called after a RAW/JPEG capture has completed; resets the AF trigger state for the
 * pre-capture sequence.
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void finishedCaptureLocked() {
    try {
        // Reset the auto-focus trigger in case AF didn't run quickly enough.
        if (!mNoAFRun) {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);

            mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback,
                    mBackgroundHandler);

            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 7
Project: Camera2Vision   File: Camera2Source.java   View source code 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 8
Project: Camera2Vision   File: Camera2Source.java   View source code 6 votes vote down vote up
public void autoFocus(@Nullable AutoFocusCallback cb, MotionEvent pEvent, int screenW, int screenH) {
    if(cb != null) {
        mAutoFocusCallback = cb;
    }
    if(sensorArraySize != null) {
        final int y = (int)pEvent.getX() / screenW * sensorArraySize.height();
        final int x = (int)pEvent.getY() / screenH * sensorArraySize.width();
        final int halfTouchWidth = 150;
        final int halfTouchHeight = 150;
        MeteringRectangle focusAreaTouch = new MeteringRectangle(
                Math.max(x-halfTouchWidth, 0),
                Math.max(y-halfTouchHeight, 0),
                halfTouchWidth*2,
                halfTouchHeight*2,
                MeteringRectangle.METERING_WEIGHT_MAX - 1);

        try {
            mCaptureSession.stopRepeating();
            //Cancel any existing AF trigger (repeated touches, etc.)
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);

            //Now add a new AF trigger with focus region
            if(isMeteringAreaAFSupported) {
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{focusAreaTouch});
            }
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
            mPreviewRequestBuilder.setTag("FOCUS_TAG"); //we'll capture this later for resuming the preview!
            //Then we ask for a single request (not repeating!)
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
        } catch(CameraAccessException ex) {
            Log.d("ASD", "AUTO FOCUS EXCEPTION: "+ex);
        }
    }
}
 
Example 9
Project: JinsMemeBRIDGE-Android   File: Camera2BasicFragment.java   View source code 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 10
Project: opencv-documentscanner-android   File: Camera2BasicFragment.java   View source code 5 votes vote down vote up
/**
     * Lock the focus as the first step for a still image capture.
     */
    private void lockFocus() {
        try {
            Log.d(TAG, "lockFocus: ");
            // This is how to tell the camera to lock focus.
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_START);
            // Tell #mCaptureCallback to wait for the lock.
//            mState = STATE_WAITING_LOCK;
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                    mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
Example 11
Project: Ocr-android   File: CameraPreview.java   View source code 5 votes vote down vote up
/**
 * 运行preCapture序列来捕获静止图像
 */
private void runPreCaptureSequence() {
    try {
        // 设置拍照参数请求
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        mState = STATE_WAITING_PRE_CAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 12
Project: CameraKitView   File: Camera2Fragment.java   View source code 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 {
            removeCaptureMessage();
            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);
//            updateAutoFocus();
            updateFlash(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) {
                    unlockFocus();
                }
            };

            mPreviewSession.stopRepeating();
            mPreviewSession.capture(captureBuilder.build(), CaptureCallback, mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
Example 13
Project: CameraFragment   File: Camera2Manager.java   View source code 5 votes vote down vote up
private void runPreCaptureSequence() {
    try {
        previewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        previewState = STATE_WAITING_PRE_CAPTURE;
        captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler);
    } catch (CameraAccessException e) {
    }
}
 
Example 14
Project: CameraFragment   File: Camera2Manager.java   View source code 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 15
Project: CameraFragment   File: Camera2Manager.java   View source code 5 votes vote down vote up
private void unlockFocus() {
    try {
        previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler);
        previewState = STATE_PREVIEW;
        captureSession.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler);
    } catch (Exception e) {
        Log.e(TAG, "Error during focus unlocking");
    }
}
 
Example 16
Project: CameraFragment   File: Camera2Manager.java   View source code 5 votes vote down vote up
private void setFlashModeAndBuildPreviewRequest(@Configuration.FlashMode int flashMode) {
    try {

        switch (flashMode) {
            case Configuration.FLASH_MODE_AUTO:
                previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
                previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
                break;
            case Configuration.FLASH_MODE_ON:
                previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
                previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
                break;
            case Configuration.FLASH_MODE_OFF:
                previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
                previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
                break;
            default:
                previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
                previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_SINGLE);
                break;
        }

        previewRequest = previewRequestBuilder.build();

        try {
            captureSession.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler);
        } catch (Exception e) {
            Log.e(TAG, "Error updating preview: ", e);
        }
    } catch (Exception ignore) {
        Log.e(TAG, "Error setting flash: ", ignore);
    }
}
 
Example 17
Project: Ocr-android   File: CameraPreview.java   View source code 5 votes vote down vote up
/**
 * 解锁焦点
 */
private void unlockFocus() {
    try {
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 18
Project: JinsMemeBRIDGE-Android   File: Camera2BasicFragment.java   View source code 5 votes vote down vote up
/**
 * Lock the focus as the first step for a still image capture.
 */
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 19
Project: Ocr-android   File: CameraPreview.java   View source code 5 votes vote down vote up
/**
 * 锁定焦点
 */
private void lockFocus() {
    try {
        // 如何通知相机锁定焦点
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
        // 通知mCaptureCallback等待锁定
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 20
Project: Android-Code-Demos   File: Camera2BasicFragment.java   View source code 5 votes vote down vote up
/**
 * Lock the focus as the first step for a still image capture.
 */
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 21
Project: Android-Code-Demos   File: Camera2BasicFragment.java   View source code 5 votes vote down vote up
/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 */
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 22
Project: EvilsLive   File: CameraNew.java   View source code 5 votes vote down vote up
private void reconfigureCamera() {
    if(mCamera != null) {
        try {
            mCaptureSession.stopRepeating();

            mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
            mCaptureSession.capture(mPreviewBuilder.build(), mPreCaptureCallback, mHandler);

            doPreviewConfiguration();
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
}
 
Example 23
Project: Android-Code-Demos   File: MyCamera2Fragment.java   View source code 5 votes vote down vote up
@Override
public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
                                CaptureResult partialResult) {
    Log.d(TAG, "mSessionCaptureCallback,  onCaptureProgressed");
    mSession = session;
    checkState(partialResult);
}
 
Example 24
Project: android-camera2-secret-picture-taker   File: PictureCapturingServiceImpl.java   View source code 5 votes vote down vote up
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request,
                               @NonNull TotalCaptureResult result) {
    super.onCaptureCompleted(session, request, result);
    if (picturesTaken.lastEntry() != null) {
        capturingListener.onCaptureDone(picturesTaken.lastEntry().getKey(), picturesTaken.lastEntry().getValue());
        Log.i(TAG, "done taking picture from camera " + cameraDevice.getId());
    }
    closeCamera();
}
 
Example 25
Project: PXLSRT   File: Camera2.java   View source code 5 votes vote down vote up
@Override
public void onPrecaptureRequired() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
            CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
    setState(STATE_PRECAPTURE);
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), this, null);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_IDLE);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to run precapture sequence.", e);
    }
}
 
Example 26
Project: PXLSRT   File: Camera2.java   View source code 5 votes vote down vote up
/**
 * Updates the internal state of flash to {@link #mFlash}.
 */
void updateFlash() {
    switch (mFlash) {
        case Constants.FLASH_OFF:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
        case Constants.FLASH_ON:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
        case Constants.FLASH_TORCH:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_TORCH);
            break;
        case Constants.FLASH_AUTO:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
        case Constants.FLASH_RED_EYE:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
    }
}
 
Example 27
Project: PXLSRT   File: Camera2.java   View source code 5 votes vote down vote up
/**
 * Locks the focus as the first step for a still image capture.
 */
private void lockFocus() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_START);
    try {
        mCaptureCallback.setState(PictureCaptureCallback.STATE_LOCKING);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to lock focus.", e);
    }
}
 
Example 28
Project: BWS-Android   File: CameraHelperTest.java   View source code 5 votes vote down vote up
@Test
public void testSetupCaptureRequestForPreview_captureRequestBuilderIsConfiguredCorrectly() throws Exception {
    cameraHelper.setupCaptureRequestForPreview(session, camera, surfaces);
    verify(captureRequestBuilder).addTarget(surface1);
    verify(captureRequestBuilder).addTarget(surface2);
    verify(captureRequestBuilder).set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
}
 
Example 29
Project: OkayCamera-Android   File: OkCaptureRequestBuilder.java   View source code 5 votes vote down vote up
/**
 * Build a request using the current target Surfaces and settings.
 * @return CaptureRequest
 * @throws ObjectNotInitializedException You should call init() before call this method otherwise
 * it will throw a ObjectNotInitializedException
 */
public CaptureRequest build() throws ObjectNotInitializedException {
    if (mBuilder != null) {
        return mBuilder.build();
    } else {
        throw genException();
    }
}
 
Example 30
Project: Camera_Calibration_Android   File: Camera2BasicFragment.java   View source code 5 votes vote down vote up
/**
 * Lock the focus as the first step for a still image capture.
 */
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 31
Project: OkayCamera-Android   File: CaptureModel.java   View source code 5 votes vote down vote up
@Override
public void buildRequest(int type) {
    try {
        CaptureRequest.Builder builder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }

}
 
Example 32
Project: phonk   File: CameraNew2.java   View source code 5 votes vote down vote up
public void qq() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_EFFECT_MODE, CaptureResult.CONTROL_EFFECT_MODE_MONO);
    mPreviewRequest = mPreviewRequestBuilder.build();
    try {
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 33
Project: LongImageCamera   File: Camera2.java   View source code 5 votes vote down vote up
@Override
public void onPrecaptureRequired() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
            CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
    setState(STATE_PRECAPTURE);
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), this, null);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_IDLE);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to run precapture sequence.", e);
    }
}
 
Example 34
Project: VideoCRE   File: Camera2Session.java   View source code 5 votes vote down vote up
private void chooseFocusMode(CaptureRequest.Builder captureRequestBuilder) {
  final int[] availableFocusModes =
      cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
  for (int mode : availableFocusModes) {
    if (mode == CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO) {
      captureRequestBuilder.set(
          CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO);
      Logging.d(TAG, "Using continuous video auto-focus.");
      return;
    }
  }
  Logging.d(TAG, "Auto-focus is not available.");
}
 
Example 35
Project: android-robocar   File: CaptureCallback.java   View source code 5 votes vote down vote up
@Override
public void onCaptureStarted(@NonNull CameraCaptureSession session,
                             @NonNull CaptureRequest request, long timestamp, long frameNumber) {
  super.onCaptureStarted(session, request, timestamp, frameNumber);
  Timber.d("Capture started.");
  this.session = session;
}
 
Example 36
Project: CameraKitView   File: Camera2Fragment.java   View source code 5 votes vote down vote up
/**
 * Updates the internal state of flash to {@link #mFlash}.
 */
void updateFlash(CaptureRequest.Builder requestBuilder) {
    if (!mFlashSupported) {
        return;
    }
    switch (mFlash) {
        case CameraConstants.FLASH_OFF:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON);
            requestBuilder.set(CaptureRequest.FLASH_MODE,
                CaptureRequest.FLASH_MODE_OFF);
            break;
        case CameraConstants.FLASH_ON:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
            requestBuilder.set(CaptureRequest.FLASH_MODE,
                CaptureRequest.FLASH_MODE_OFF);
            break;
        case CameraConstants.FLASH_TORCH:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON);
            requestBuilder.set(CaptureRequest.FLASH_MODE,
                CaptureRequest.FLASH_MODE_TORCH);
            break;
        case CameraConstants.FLASH_AUTO:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
            requestBuilder.set(CaptureRequest.FLASH_MODE,
                CaptureRequest.FLASH_MODE_OFF);
            break;
        case CameraConstants.FLASH_RED_EYE:
            requestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE);
            requestBuilder.set(CaptureRequest.FLASH_MODE,
                CaptureRequest.FLASH_MODE_OFF);
            break;
    }
}
 
Example 37
Project: phonk   File: CameraNew2.java   View source code 5 votes vote down vote up
private void unlockFocus() {
    MLog.d(TAG, "unlockFocus");

    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        //setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 38
Project: hella-renderscript   File: CameraOps.java   View source code 5 votes vote down vote up
/**
 * Get a request builder for the current camera.
 */
public CaptureRequest.Builder createCaptureRequest(int template) throws CameraAccessException {
    CameraDevice device = mCameraDevice;
    if (device == null) {
        throw new IllegalStateException("Can't get requests when no camera is open");
    }
    return device.createCaptureRequest(template);
}
 
Example 39
Project: hella-renderscript   File: CameraOps.java   View source code 5 votes vote down vote up
/**
 * Set a repeating request.
 */
public void setRepeatingRequest(final CaptureRequest request,
        final CameraCaptureSession.CaptureCallback listener, final Handler handler) {
    mCameraHandler.post(() -> {
        try {
            mCameraSession.setRepeatingRequest(request, listener, handler);
        } catch (CameraAccessException e) {
            String errorMessage = mErrorDisplayer.getErrorString(e);
            mErrorDisplayer.showErrorDialog(errorMessage);
        }
    });
}
 
Example 40
Project: hella-renderscript   File: BaseViewfinderActivity.java   View source code 5 votes vote down vote up
/**
 * Callbacks for CameraOps {@link CameraOps.CameraReadyListener}.
 */
@Override
public void onCameraReady() {
    // Ready to send requests in, so set them up
    try {
        CaptureRequest.Builder previewBuilder =
                mCameraOps.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        previewBuilder.addTarget(mProcessingNormalSurface);
        mCameraOps.setRepeatingRequest(previewBuilder.build(), null, mUiHandler);

    } catch (CameraAccessException e) {
        String errorMessage = getErrorString(e);
        showErrorDialog(errorMessage);
    }
}