Example usage for android.hardware.camera2 CameraCharacteristics LENS_FACING

List of usage examples for android.hardware.camera2 CameraCharacteristics LENS_FACING

Introduction

In this page you can find the example usage for android.hardware.camera2 CameraCharacteristics LENS_FACING.

Prototype

Key LENS_FACING

To view the source code for android.hardware.camera2 CameraCharacteristics LENS_FACING.

Click Source Link

Document

Direction the camera faces relative to device screen.

Possible values:

  • #LENS_FACING_FRONT FRONT
  • #LENS_FACING_BACK BACK
  • #LENS_FACING_EXTERNAL EXTERNAL

This key is available on all devices.

Usage

From source file:com.quectel.camera2test.Camera2RawFragment.java

/**
 * Rotation need to transform from the camera sensor orientation to the device's current
 * orientation./*from  w w w .  ja v  a 2 s.c  o  m*/
 *
 * @param c                 the {@link CameraCharacteristics} to query for the camera sensor
 *                          orientation.
 * @param deviceOrientation the current device orientation relative to the native device
 *                          orientation.
 * @return the total rotation from the sensor orientation to the current device orientation.
 */
private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
    int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

    // Get device orientation in degrees
    deviceOrientation = ORIENTATIONS.get(deviceOrientation);

    // Reverse device orientation for front-facing cameras
    if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
        deviceOrientation = -deviceOrientation;
    }

    // Calculate desired JPEG orientation relative to camera orientation to make
    // the image upright relative to the device orientation
    return (sensorOrientation - deviceOrientation + 360) % 360;
}

From source file:com.ape.camera2raw.Camera2RawFragment.java

/**
 * Rotation need to transform from the camera sensor orientation to the device's current
 * orientation.//from w w  w  .  j  ava2 s .  co  m
 *
 * @param c                 the {@link CameraCharacteristics} to query for the camera sensor
 *                          orientation.
 * @param deviceOrientation the current device orientation relative to the native device
 *                          orientation.
 * @return the total rotation from the sensor orientation to the current device orientation.
 */
private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) {
    int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

    // Get device orientation in degrees
    deviceOrientation = ORIENTATIONS.get(deviceOrientation);

    // Reverse device orientation for front-facing cameras
    if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) {
        deviceOrientation = -deviceOrientation;
    }

    // Calculate desired JPEG orientation relative to camera orientation to make
    // the image upright relative to the device orientation
    return (sensorOrientation + deviceOrientation + 360) % 360;
}