Example usage for android.hardware.camera2 CameraCharacteristics SENSOR_ORIENTATION

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

Introduction

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

Prototype

Key SENSOR_ORIENTATION

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

Click Source Link

Document

Clockwise angle through which the output image needs to be rotated to be upright on the device screen in its native orientation.

Also defines the direction of rolling shutter readout, which is from top to bottom in the sensor's coordinate system.

Units: Degrees of clockwise rotation; always a multiple of 90

Range of valid values:
0, 90, 180, 270

This key is available on all devices.

Usage

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.  jav 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;
}