Android5.1.1 自带Camera2/SnapdragonCamera的apk拍照方向旋转90°
2016-07-28 16:47
543 查看
实际上这个原因是因为机器里没有重力感应器造成的。
根据Camera2/src/com/android/camera/PhotoModule.java 的代码查看原因。
160 // The degrees of the device rotated clockwise from its natural orientation.
………………
1298 // Set JPEG orientation. Even if screen UI is locked in portrait, camera orientation should
1299 // still match device orientation (e.g., users should always get landscape photos while
1300 // capturing by putting device in landscape.)
可以得知这里是和设置角度有关的,可是查找全篇得知mOrientation只在如下代码片段修改
1347 @Override
1348 public void onOrientationChanged(int orientation) {
1349 if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
1350 return;
1351 }
1352
1353 // TODO: Document orientation compute logic and unify them in OrientationManagerImpl.
1354 // b/17443789
1355 // Flip to counter-clockwise orientation.
1356 mOrientation = (360 - orientation) % 360;
1357 }这个函数在由方向传感器发生变化后才触发,实际上是由PhotoModule继承的接口SensorEventListener有关。
101 public class PhotoModule
102 extends CameraModule
103 implements PhotoController,
104 ModuleController,
105 MemoryListener,
106 FocusOverlayManager.Listener,
107 SensorEventListener,
108 SettingsManager.OnSettingChangedListener,
109 RemoteCameraModule,
110 CountDownView.OnCountDownStatusListener 因此在没有开启自动旋转或者没有方向传感器的时候可以将
-- private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;++ private int mOrientation = 270;
搞定!
根据Camera2/src/com/android/camera/PhotoModule.java 的代码查看原因。
160 // The degrees of the device rotated clockwise from its natural orientation.
<span style="white-space:pre"> </span>// 设备的角度旋转按顺时针旋转的自然方向
161 private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
………………
1298 // Set JPEG orientation. Even if screen UI is locked in portrait, camera orientation should
1299 // still match device orientation (e.g., users should always get landscape photos while
1300 // capturing by putting device in landscape.)
1301 int orientation = mActivity.isAutoRotateScreen() ? mDisplayRotation : mOrientation;//是否自动旋转的屏幕? 1302 Characteristics info = mActivity.getCameraProvider().getCharacteristics(mCameraId); 1303 mJpegRotation = info.getJpegOrientation(orientation);//利用orientation获得Jpeg的方向 1304 mCameraDevice.setJpegOrientation(mJpegRotation);//设置输出的Jpeg方向
可以得知这里是和设置角度有关的,可是查找全篇得知mOrientation只在如下代码片段修改
1347 @Override
1348 public void onOrientationChanged(int orientation) {
1349 if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
1350 return;
1351 }
1352
1353 // TODO: Document orientation compute logic and unify them in OrientationManagerImpl.
1354 // b/17443789
1355 // Flip to counter-clockwise orientation.
1356 mOrientation = (360 - orientation) % 360;
1357 }这个函数在由方向传感器发生变化后才触发,实际上是由PhotoModule继承的接口SensorEventListener有关。
101 public class PhotoModule
102 extends CameraModule
103 implements PhotoController,
104 ModuleController,
105 MemoryListener,
106 FocusOverlayManager.Listener,
107 SensorEventListener,
108 SettingsManager.OnSettingChangedListener,
109 RemoteCameraModule,
110 CountDownView.OnCountDownStatusListener 因此在没有开启自动旋转或者没有方向传感器的时候可以将
-- private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;++ private int mOrientation = 270;
搞定!
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories