camera2中的图像旋转问题

时间:2018-05-12 07:39:38

标签: android android-camera2

我已经提到了camera2 api的google示例。在大多数设备上它工作正常但在诺基亚6.1上每次我点击一个纵向模式并在图像视图上显示它它被显示为风景。

我试过

private int getOrientation(int rotation) {
    // Sensor orientation is 90 for most devices, or 270 for some devices (eg. Nexus 5X)
    // We have to take that into account and rotate JPEG properly.
    // For devices with orientation of 90, we simply return our mapping from ORIENTATIONS.
    // For devices with orientation of 270, we need to rotate the JPEG 180 degrees.
    return (ORIENTATIONS.get(rotation) + mSensorOrientation + 270) % 360;
}

以及

private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) {
    if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0;
    int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION);

    // Round device orientation to a multiple of 90
    deviceOrientation = (deviceOrientation + 45) / 90 * 90;

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

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

    return jpegOrientation;
}

用于在CaptureRequest.Builder中设置JPEG_ORIENTATION,但它们都不适用于我

我从这两种方法获得的值是90,但这不会以任何方式影响jpeg文件。而对于诺基亚1和xiomi上的类似结果,4生成的jpeg文件是正确的(即在点击肖像图像时,肖像jpeg保存在文件系统中)

PS: - 诺基亚6.1是Android One设备(如果这与错误结果有关)

0 个答案:

没有答案