android中前后camera预览和拍照时方向是根据什么确立的?
还有横或竖着拿手机时的方向?

解决方案 »

  1.   

    private void setDisplayOrientation(Context context){
    int rotation = ((Activity) context).getWindowManager()
               .getDefaultDisplay().getRotation();
    int degree = 0;
    switch (rotation) {
    case Surface.ROTATION_0: degree = 0; break;
    case Surface.ROTATION_90: degree = 90; break;
    case Surface.ROTATION_180: degree = 180; break;
    case Surface.ROTATION_270: degree = 270; break;
    }
    int result;
    CameraInfo info = new CameraInfo();
    //Camera.getCameraInfo(mBackCameraId, info);
    Camera.getCameraInfo(0, info);
    if(info.facing == CameraInfo.CAMERA_FACING_FRONT){
    result = (info.orientation + degree) % 360;
    result = (360 - result) % 360;
    }else{
    result =(info.orientation - degree + 360 ) % 360;
    }
    mCamera.setDisplayOrientation(result);
    Log.v("shenwenjian","result:"+result);
    pictureOrientation = result;
    }
      

  2.   

    Camera的setDisplayOrientation方法注解上有现成代码可用,和2楼的方法一样,楼主多看API
      

  3.   

    关于照片预览的方向 是exif 信息的事情。你可以google一下 android exif 就OK了