錄像保存時,旋轉角度要與所拍錄像時的角度保持一致,否則,看起來就會出現角度不度,巔倒等問題。
一般在開始錄像之前會先去初始化錄像
initializeRecorder 中會去讀取當前的錄像或拍照的旋轉角度,並跟據當前的角度來選擇一個角度寫到所拍
照片或者視頻的 exif 信息中去。
1 // See android.hardware.Camera.Parameters.setRotation for 2 // documentation. 3 // Note that mOrientation here is the device orientation, which is the opposite of 4 // what activity.getWindowManager().getDefaultDisplay().getRotation() would return, 5 // which is the orientation the graphics need to rotate in order to render correctly. 6 int rotation = 0; 7 if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) { 8 CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; 9 if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { 10 rotation = (info.orientation - mOrientation + 360) % 360; 11 } else { // back-facing camera 12 rotation = (info.orientation + mOrientation) % 360; 13 } 14 } else { 15 //Get the right original orientation 16 CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; 17 rotation = info.orientation; 18 } 19 // mMediaRecorder.setOrientationHint(rotation); 20 21 if (mCameraId == CameraInfo.CAMERA_FACING_FRONT) { 22 if (rotation == 270 || rotation == 90 || rotation == 180) { 23 mMediaRecorder.setOrientationHint(180); 24 } else { 25 mMediaRecorder.setOrientationHint(0); 26 } 27 } else { 28 if (rotation == 180){ 29 mMediaRecorder.setOrientationHint(180); 30 }else{ 31 mMediaRecorder.setOrientationHint(0); 32 } 33 }