本文整理匯總了Java中android.hardware.camera2.CameraDevice類的典型用法代碼示例。如果您正苦於以下問題:Java CameraDevice類的具體用法?Java CameraDevice怎麽用?Java CameraDevice使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CameraDevice類屬於android.hardware.camera2包,在下文中一共展示了CameraDevice類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupCaptureRequestForPreview
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
/**
* does setup the repeating capture request for taking images for the preview
*/
@VisibleForTesting
void setupCaptureRequestForPreview(@NonNull CameraCaptureSession previewSession, @NonNull CameraDevice camera,
@NonNull List<Surface> surfaces) {
try {
CaptureRequest.Builder previewRequestBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
for (Surface surface : surfaces) {
previewRequestBuilder.addTarget(surface);
}
previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
previewSession.setRepeatingRequest(previewRequestBuilder.build(), null, null);
} catch (CameraAccessException | IllegalStateException e) {
throw new CameraException(e);
}
}
示例2: startPreview
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
private void startPreview() {
try {
CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
StreamConfigurationMap configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size previewSize = Util.getPreferredPreviewSize(
configMap.getOutputSizes(ImageFormat.JPEG),textureView.getWidth(), textureView.getHeight());
surfaceTexture.setDefaultBufferSize(previewSize.getWidth(),previewSize.getHeight());
Surface surface = new Surface(surfaceTexture);
captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
captureBuilder.addTarget(surface);
cameraDevice.createCaptureSession(Arrays.asList(surface),captureSessionCallback,backgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例3: createCameraPreviewSession
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
private void createCameraPreviewSession() {
if (mCamera == null) {
return;
}
SurfaceHolder holder = surfaceView.getHolder();
// if (config != null) {
// holder.setFixedSize(640, 480);
// }
Surface surface = holder.getSurface();
List<Surface> surfaceList = Arrays.asList(surface, mImageReader.getSurface());
try {
mPreviewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewBuilder.addTarget(surface);
mCamera.createCaptureSession(surfaceList, sessionCallback, mHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
示例4: onOpened
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(CameraDevice camera) {
checkIsOnCameraThread();
Logging.d(TAG, "Camera opened.");
cameraDevice = camera;
final SurfaceTexture surfaceTexture = surfaceTextureHelper.getSurfaceTexture();
surfaceTexture.setDefaultBufferSize(captureFormat.width, captureFormat.height);
surface = new Surface(surfaceTexture);
List<Surface> surfaces = new ArrayList<Surface>();
surfaces.add(surface);
if (mediaRecorderSurface != null) {
Logging.d(TAG, "Add MediaRecorder surface to capture session.");
surfaces.add(mediaRecorderSurface);
}
try {
camera.createCaptureSession(surfaces, new CaptureSessionCallback(), cameraThreadHandler);
} catch (CameraAccessException e) {
reportError("Failed to create capture session. " + e);
return;
}
}
示例5: getErrorDescription
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
private String getErrorDescription(int errorCode) {
switch (errorCode) {
case CameraDevice.StateCallback.ERROR_CAMERA_DEVICE:
return "Camera device has encountered a fatal error.";
case CameraDevice.StateCallback.ERROR_CAMERA_DISABLED:
return "Camera device could not be opened due to a device policy.";
case CameraDevice.StateCallback.ERROR_CAMERA_IN_USE:
return "Camera device is in use already.";
case CameraDevice.StateCallback.ERROR_CAMERA_SERVICE:
return "Camera service has encountered a fatal error.";
case CameraDevice.StateCallback.ERROR_MAX_CAMERAS_IN_USE:
return "Camera device could not be opened because"
+ " there are too many other open camera devices.";
default:
return "Unknown camera error: " + errorCode;
}
}
示例6: onClosed
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onClosed(CameraDevice cameraDevice) {
Logging.d(TAG, "Simple camera2 closed.");
synchronized (cameraDeviceLock) {
SimpleCamera2.this.cameraDevice = null;
}
}
示例7: onOpened
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(final CameraDevice cd) {
// This method is called when the camera is opened. We start camera preview here.
cameraOpenCloseLock.release();
cameraDevice = cd;
createCameraPreviewSession();
}
示例8: onOpened
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(@NonNull CameraDevice cameraDevice) {
// This method is called when the camera is opened. We start camera preview here.
mCameraOpenCloseLock.release();
mCameraDevice = cameraDevice;
createCameraPreviewSession();
}
示例9: onError
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onError(@NonNull CameraDevice cameraDevice, int error) {
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
Activity activity = getActivity();
if (null != activity) {
activity.finish();
}
}
示例10: onClosed
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onClosed(@NonNull CameraDevice camera) {
cameraClosed = true;
Log.d(TAG, "camera " + camera.getId() + " closed");
//once the current camera has been closed, start taking another picture
if (!cameraIds.isEmpty()) {
takeAnotherPicture();
} else {
capturingListener.onDoneCapturingAllPhotos(picturesTaken);
}
}
開發者ID:botyourbusiness,項目名稱:android-camera2-secret-picture-taker,代碼行數:12,代碼來源:PictureCapturingServiceImpl.java
示例11: triggerImageCapture
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
/**
* Execute a new capture request within the active session
*/
private void triggerImageCapture() {
try {
final CaptureRequest.Builder captureBuilder =
mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(mImageReader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
Log.d(TAG, "Capture request created.");
mCaptureSession.capture(captureBuilder.build(), mCaptureCallback, null);
} catch (CameraAccessException cae) {
Log.d(TAG, "camera capture exception");
} catch (IllegalStateException e) {
Log.d(TAG, "camera freaked out");
}
}
示例12: onOpened
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(final CameraDevice cd) {
// This method is called when the camera is opened. We start camera preview here.
cameraOpenCloseLock.release();
cameraDevice = cd;
createCameraPreviewSession();
}
示例13: captureStillPicture
import android.hardware.camera2.CameraDevice; //導入依賴的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 {
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();
}
}
示例14: onOpened
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onOpened(CameraDevice cameraDevice) {
Camera2Manager.this.cameraDevice = cameraDevice;
if (cameraOpenListener != null) {
uiHandler.post(new Runnable() {
@Override
public void run() {
if (!TextUtils.isEmpty(currentCameraId) && previewSize != null)
cameraOpenListener.onCameraOpened(currentCameraId, previewSize, Camera2Manager.this);
}
});
}
}
示例15: onDisconnected
import android.hardware.camera2.CameraDevice; //導入依賴的package包/類
@Override
public void onDisconnected(CameraDevice cameraDevice) {
cameraDevice.close();
Camera2Manager.this.cameraDevice = null;
uiHandler.post(new Runnable() {
@Override
public void run() {
cameraOpenListener.onCameraOpenError();
}
});
}