当前位置: 首页>>代码示例>>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;未经允许,请勿转载。