如何在所有设备中保持相机处于纵向模式?我的应用高于 2.2
我试过了
public void setRotation(int rotation) {
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;
CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(cameraId, cameraInfo);
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;
}
mCamera.stopPreview();
mCamera.setDisplayOrientation(result);
mCamera.startPreview();
}
但三星设备忽略mCamera.setDisplayOrientation(90)
编辑:
我发现忽略了这一点的设备:
Galaxy y(GT-S5360)(Android 2.3.6)
银河王牌(GT-S5830)(Android 2.6.3)
但 Galaxy S2 和其他更高版本的手机运行良好。