Android相机旋转为肖像模式图片

时间:2014-03-14 05:25:52

标签: android android-camera

1 个答案:

答案 0 :(得分:0)

请查看setRotation() sample

public void onOrientationChanged(int orientation) {
     if (orientation == ORIENTATION_UNKNOWN) return;
     android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
     android.hardware.Camera.getCameraInfo(cameraId, info);
     orientation = (orientation + 45) / 90 * 90;
     int rotation = 0;
     if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
         rotation = (info.orientation - orientation + 360) % 360;
     } else {  // back-facing camera
         rotation = (info.orientation + orientation) % 360;
     }
     mParameters.setRotation(rotation);
}
与方向传感器不同,

Display.getRotation()仅限于当前活动支持的方向。在某些设备上,系统不支持纵向倒置方向。