下面列出了android.hardware.camera2.CameraMetadata#LENS_FACING_FRONT 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
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();
}
@Override
public boolean isFrontFacing(String deviceName) {
CameraCharacteristics characteristics = getCameraCharacteristics(deviceName);
return characteristics != null
&& characteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_FRONT;
}
/**
* Given the device orientation and Camera2 characteristics, this returns
* the required JPEG rotation for this camera.
*
* @param deviceOrientationDegrees the clockwise angle of the device orientation from its
* natural orientation in degrees.
* @return The angle to rotate image clockwise in degrees. It should be 0, 90, 180, or 270.
*/
public static int getJpegRotation(int deviceOrientationDegrees,
CameraCharacteristics characteristics)
{
if (deviceOrientationDegrees == OrientationEventListener.ORIENTATION_UNKNOWN)
{
return 0;
}
boolean isFrontCamera = characteristics.get(CameraCharacteristics.LENS_FACING) ==
CameraMetadata.LENS_FACING_FRONT;
int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
return getImageRotation(sensorOrientation, deviceOrientationDegrees, isFrontCamera);
}
public OneCamera.Facing getDirection()
{
switch (mCharacteristics.get(CameraCharacteristics.LENS_FACING))
{
case CameraMetadata.LENS_FACING_BACK:
return OneCamera.Facing.BACK;
case CameraMetadata.LENS_FACING_FRONT:
return OneCamera.Facing.FRONT;
}
return OneCamera.Facing.BACK;
}
@Override
public boolean isFrontFacing(String deviceName) {
CameraCharacteristics characteristics = getCameraCharacteristics(deviceName);
return characteristics != null
&& characteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_FRONT;
}
private static int getFacing(CameraHelper.Facing facing) {
return facing == CameraHelper.Facing.BACK ? CameraMetadata.LENS_FACING_BACK
: CameraMetadata.LENS_FACING_FRONT;
}