禁用屏幕旋转后,手动设置camera预览方向

来源:互联网 发布:sql中insert into语句 编辑:程序博客网 时间:2024/06/10 12:13
public  void setCameraDisplayOrientation() {    if(null==mCamera)        return;    android.hardware.Camera.CameraInfo info =            new android.hardware.Camera.CameraInfo();
    //这里的cameraid指的是前后摄像头的设置,0是后摄像头,1是前摄像头    android.hardware.Camera.getCameraInfo(mCameraId, info);    int rotation = GlobalUtil.getMainActivity().getWindowManager().getDefaultDisplay()            .getRotation();    int degrees = 0;    switch (rotation) {        case Surface.ROTATION_0: degrees = 0; break;        case Surface.ROTATION_90: degrees = 90; break;        case Surface.ROTATION_180: degrees = 180; break;        case Surface.ROTATION_270: degrees = 270; break;    }    int result;    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {        result = (info.orientation + degrees) % 360;        result = (360 - result) % 360;  // compensate the mirror    } else {  // back-facing        result = (info.orientation - degrees + 360) % 360;    }    if (Log.isLoggable(LogTag.ADAS, Log.DEBUG)) {        Log.d(LogTag.ADAS, "DisplayOrientation: "+result);    }    mCamera.setDisplayOrientation(result);}