【发布时间】:2016-05-17 17:12:34
【问题描述】:
我有一个使用安卓设备摄像头的应用程序。拍照的activity不能旋转,只能纵向显示。 在大多数设备上,此代码都可以正常工作:
int degrees = 0;
int rotation = activity.getWindowManager().getDefaultDisplay()
.getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
int result;
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (cameraInfo.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (cameraInfo.orientation - degrees + 360) % 360;
} camera.setDisplayOrientation(result);
但在设备(DMTECH 725H,7 英寸平板电脑,只有前置摄像头)上,预览显示是颠倒的。有任何解决方法的想法吗?
【问题讨论】:
-
此设备是否正确将
cameraInfo.facing设置为CAMERA_FACING_FRONT,还是说相机朝后? -
我不知道,我无法在设备上调试应用程序,但我尝试将相机旋转 90 度和 270 度,结果是一样的
-
我在 Nexus 5X (6.0.1) 中遇到了同样的问题