android Camera 录像时旋转角度
录像保存时,旋转角度要与所拍录像时的角度保持一致,否则,看起来就会出现角度不度,巅倒等问题。
一般在开始录像之前会先去初始化录像
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 }
联系方式:emhhbmdfbGlhbmcxOTkxQDEyNi5jb20=
分类:
Android-Camera
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了