本文整理汇总了Java中android.hardware.camera2.CameraMetadata类的典型用法代码示例。如果您正苦于以下问题:Java CameraMetadata类的具体用法?Java CameraMetadata怎么用?Java CameraMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CameraMetadata类属于android.hardware.camera2包,在下文中一共展示了CameraMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unlockFocus
import android.hardware.camera2.CameraMetadata; //导入依赖的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();
}
}
示例2: autoFocus
import android.hardware.camera2.CameraMetadata; //导入依赖的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);
}
}
}
示例3: unlockFocus
import android.hardware.camera2.CameraMetadata; //导入依赖的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);
if(mFlashSupported) {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode);
}
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();
}
}
示例4: switchHdrMode
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
private void switchHdrMode() {
switch (mHdrMode) {
case 0:
mHdrMode = 1;
mIvHdr.setImageResource(R.mipmap.hdr_on);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_HDR);
break;
case 1:
mHdrMode = 0;
mIvHdr.setImageResource(R.mipmap.hdr_off);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_DISABLED);
break;
}
try {
mCaptureSession.setRepeatingRequest(
mPreviewRequestBuilder.build(),
mPreCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
return;
}
}
示例5: finishedCaptureLocked
import android.hardware.camera2.CameraMetadata; //导入依赖的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();
}
}
示例6: start
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
private void start() {
checkIsOnCameraThread();
Logging.d(TAG, "start");
try {
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
} catch (final CameraAccessException e) {
reportError("getCameraCharacteristics(): " + e.getMessage());
return;
}
cameraOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
isCameraFrontFacing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_FRONT;
findCaptureFormat();
openCamera();
}
示例7: unlockFocus
import android.hardware.camera2.CameraMetadata; //导入依赖的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);
mPreviewSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
updateAutoFocus();
updateFlash(mPreviewRequestBuilder);
// After this, the camera will go back to the normal state of preview.
mState = STATE_PREVIEW;
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
mPreviewSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例8: doPreviewConfiguration
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
private void doPreviewConfiguration() {
if (mCamera == null) {
return;
}
try {
// mPreviewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
// mPreviewBuilder.addTarget(surfaceView.getHolder().getSurface());
// mPreviewBuilder.addTarget(mImageReader.getSurface());
mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
// mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
// mPreviewBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
// mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
mPreviewBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, mFps[mFps.length -1 ]);
mCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreCaptureCallback, mHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例9: onOpened
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
@Override
public void onOpened(@NonNull CameraDevice camera) {
mCameraDevice = camera;
//get builder
try {
mBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL);
//flash on, default is on
mBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO);
mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
List<Surface> list = new ArrayList<>();
SurfaceTexture mSurfaceTexture = new SurfaceTexture(1);
Size size = getSmallestSize(mCameraDevice.getId());
mSurfaceTexture.setDefaultBufferSize(size.getWidth(), size.getHeight());
Surface mSurface = new Surface(mSurfaceTexture);
list.add(mSurface);
mBuilder.addTarget(mSurface);
camera.createCaptureSession(list, new MyCameraCaptureSessionStateCallback(), null);
mSurfaceTexture.release();
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例10: lockFocus
import android.hardware.camera2.CameraMetadata; //导入依赖的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)
{
LogExt.e(getClass(), e);
}
}
示例11: unlockFocus
import android.hardware.camera2.CameraMetadata; //导入依赖的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)
{
LogExt.e(getClass(), e);
LogExt.e(getClass(), e);
}
}
示例12: unlockFocus
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
private void unlockFocus() {
try {
// AFのロックを解除する(トリガーをキャンセルする)
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
// AFトリガーのキャンセルを実行する
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mInterface.getBackgroundHandler());
// プレビューを継続するためsetRepeatingRequestメソッドを実行する
mState = STATE_PREVIEW;
mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
mInterface.getBackgroundHandler());
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例13: toFile
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
/**
* Generate a human-readable string of the given capture request and write
* it to the given file.
*/
public static void toFile(String title, CameraMetadata<?> metadata, File file) {
try {
// Will append if the file already exists.
FileWriter writer = new FileWriter(file, true);
if (metadata instanceof CaptureRequest) {
dumpMetadata(title, (CaptureRequest) metadata, writer);
} else if (metadata instanceof CaptureResult) {
dumpMetadata(title, (CaptureResult) metadata, writer);
} else {
writer.close();
throw new IllegalArgumentException("Cannot generate debug data from type "
+ metadata.getClass().getName());
}
writer.close();
} catch (IOException ex) {
Log.e(TAG, "Could not write capture data to file.", ex);
}
}
示例14: repeatingPreview
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
/**
* Request preview capture stream with AF_MODE_CONTINUOUS_PICTURE.
*
* @return true if request was build and sent successfully.
* @param tag
*/
private boolean repeatingPreview(Object tag) {
try {
CaptureRequest.Builder builder = mDevice.
createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
builder.addTarget(mPreviewSurface);
builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
addBaselineCaptureKeysToRequest(builder);
mCaptureSession.setRepeatingRequest(builder.build(), mAutoFocusStateListener,
mCameraHandler);
Log.v(TAG, String.format("Sent repeating Preview request, zoom = %.2f", mZoomValue));
return true;
} catch (CameraAccessException ex) {
Log.e(TAG, "Could not access camera setting up preview.", ex);
return false;
}
}
示例15: sendAutoFocusTriggerCaptureRequest
import android.hardware.camera2.CameraMetadata; //导入依赖的package包/类
/**
* Request preview capture stream with auto focus trigger cycle.
*/
private void sendAutoFocusTriggerCaptureRequest(Object tag) {
try {
// Step 1: Request single frame CONTROL_AF_TRIGGER_START.
CaptureRequest.Builder builder;
builder = mDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
builder.addTarget(mPreviewSurface);
builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
mControlAFMode = CameraMetadata.CONTROL_AF_MODE_AUTO;
addBaselineCaptureKeysToRequest(builder);
builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
builder.setTag(tag);
mCaptureSession.capture(builder.build(), mAutoFocusStateListener, mCameraHandler);
// Step 2: Call repeatingPreview to update mControlAFMode.
repeatingPreview(tag);
resumeContinuousAFAfterDelay(FOCUS_HOLD_MILLIS);
} catch (CameraAccessException ex) {
Log.e(TAG, "Could not execute preview request.", ex);
}
}