當前位置: 首頁>>代碼示例>>Java>>正文


Java CaptureRequest類代碼示例

本文整理匯總了Java中android.hardware.camera2.CaptureRequest的典型用法代碼示例。如果您正苦於以下問題:Java CaptureRequest類的具體用法?Java CaptureRequest怎麽用?Java CaptureRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CaptureRequest類屬於android.hardware.camera2包,在下文中一共展示了CaptureRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: unlockFocus

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:vulovicv23,項目名稱:opencv-documentscanner-android,代碼行數:21,代碼來源:Camera2BasicFragment.java

示例2: finishedCaptureLocked

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:gengqifu,項目名稱:361Camera,代碼行數:24,代碼來源:Camera2Fragment.java

示例3: unlockFocus

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:vshkl,項目名稱:PXLSRT,代碼行數:21,代碼來源:Camera2.java

示例4: onCaptureFailed

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
@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;
  }
}
 
開發者ID:zugaldia,項目名稱:android-robocar,代碼行數:19,代碼來源:CaptureCallback.java

示例5: onCaptureCompleted

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:EzequielAdrianM,項目名稱:Camera2Vision,代碼行數:19,代碼來源:Camera2Source.java

示例6: autoFocus

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
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);
        }
    }
}
 
開發者ID:EzequielAdrianM,項目名稱:Camera2Vision,代碼行數:39,代碼來源:Camera2Source.java

示例7: lockFocus

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
     * 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();
        }
    }
 
開發者ID:vulovicv23,項目名稱:opencv-documentscanner-android,代碼行數:18,代碼來源:Camera2BasicFragment.java

示例8: runPreCaptureSequence

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
 * 運行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();
    }
}
 
開發者ID:shenhuanet,項目名稱:Ocr-android,代碼行數:15,代碼來源:CameraPreview.java

示例9: captureStillPicture

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
     * 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();
        }
    }
 
開發者ID:lytcom,項目名稱:CameraKitView,代碼行數:44,代碼來源:Camera2Fragment.java

示例10: runPreCaptureSequence

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
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) {
    }
}
 
開發者ID:florent37,項目名稱:CameraFragment,代碼行數:9,代碼來源:Camera2Manager.java

示例11: captureStillPicture

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
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");
    }
}
 
開發者ID:florent37,項目名稱:CameraFragment,代碼行數:29,代碼來源:Camera2Manager.java

示例12: unlockFocus

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
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");
    }
}
 
開發者ID:florent37,項目名稱:CameraFragment,代碼行數:11,代碼來源:Camera2Manager.java

示例13: setFlashModeAndBuildPreviewRequest

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
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);
    }
}
 
開發者ID:florent37,項目名稱:CameraFragment,代碼行數:34,代碼來源:Camera2Manager.java

示例14: unlockFocus

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
 * 解鎖焦點
 */
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();
    }
}
 
開發者ID:shenhuanet,項目名稱:Ocr-android,代碼行數:18,代碼來源:CameraPreview.java

示例15: lockFocus

import android.hardware.camera2.CaptureRequest; //導入依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:tkrworks,項目名稱:JinsMemeBRIDGE-Android,代碼行數:17,代碼來源:Camera2BasicFragment.java


注:本文中的android.hardware.camera2.CaptureRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。