代码片段分享

Android 拍照后方向旋转问题

2019-11-15  本文已影响0人  花艺荣
  1. 假定为 横屏应用 ,这时无需设定Camera预览时的 display orientation,当手持为横屏时(home键在右侧)无需旋转,其它手持方向都需要旋转数据。
    屏幕方向.jpg
  1. 获取屏幕方向:
mOrientationListener = new OrientationEventListener(getApplicationContext(), SensorManager.SENSOR_DELAY_NORMAL) {
     @Override
     public void onOrientationChanged(int orientation) {
               mOrientation = orientation;
          }
       };
       try {
              mOrientationListener.enable();
           } catch (Exception e) {
               log(e.toString());
           }
public static  ScreenOrientation getCameraDeviceOritation(int orientation){

       ScreenOrientation newOrientation = ScreenOrientation.LANDSCAPE;

       if (orientation >= 45 && orientation < 135)

       {
           newOrientation = ScreenOrientation.REVERSED_LANDSCAPE;

       }

       else if (orientation >= 135 && orientation < 225)

       {
           newOrientation = ScreenOrientation.REVERSED_PORTRAIT;

       }

       else if (orientation >= 225 && orientation < 315)

       {
           newOrientation = ScreenOrientation.LANDSCAPE;

       }else if((orientation >= 315 && orientation<=360) || (orientation>=0&&orientation < 45))
       {
           newOrientation = ScreenOrientation.PORTRAIT;
       }

       return newOrientation;

   }
  1. 根据屏幕角度旋转
上一篇下一篇

猜你喜欢

热点阅读