安卓(Android) 怎么获取预览方向度

2019年10月27日22:37:05安卓(Android) 怎么获取预览方向度已关闭评论 185 744字阅读2分28秒

1.简介

安卓(Android) 怎么获取预览方向度?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

 


import android.util.Log;

public class Main {
    private static final String LOG_TAG = "CameraUtilities";

    public static int getPreviewOrientationDegrees(
            int screenOrientationDegrees, Integer cameraOrientationDegrees,
            boolean usingFrontCamera) {

        int previewOrientationDegrees = 0;

        if (cameraOrientationDegrees != null) {
            if (usingFrontCamera) { 
                previewOrientationDegrees = (cameraOrientationDegrees + screenOrientationDegrees) % 360;
                previewOrientationDegrees = (360 - previewOrientationDegrees) % 360;
            } else { 
                previewOrientationDegrees = (cameraOrientationDegrees
                        - screenOrientationDegrees + 360) % 360;
            }
        } else {
            
            Log.d(LOG_TAG,
                    "Unable to detect camera orientation - setting to 0");
            previewOrientationDegrees = 0;
        }

        return previewOrientationDegrees;
    }
}

 
编程十万个怎么办