【问题标题】:Why does my Android Camera Preview show landscape even if I have set Application Manifest to the Portrait?即使我将应用程序清单设置为纵向,为什么我的 Android 相机预览仍显示横向?
【发布时间】:2011-12-18 17:54:24
【问题描述】:

在我的 Android 相机应用程序中,我已将我的应用程序清单设置为肖像。但是当我正在运行我的相机应用程序时,相机预览显示为横向而不是纵向。

我不知道问题出在哪里,但我需要帮助。 我想将我的相机预览设置为像普通相机预览一样显示。并将应用设置为纵向。

有什么解决办法吗?

【问题讨论】:

标签: android android-layout android-camera


【解决方案1】:

Camera.setDisplayOrientation(90); 应该可以做到这一点,只要它保持纵向。

另外,根据文档:

public static void setCameraDisplayOrientation(Activity activity,
         int cameraId, android.hardware.Camera camera) {
   android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
   android.hardware.Camera.getCameraInfo(cameraId, info);
   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 (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
       result = (info.orientation + degrees) % 360;
       result = (360 - result) % 360;  // compensate the mirror
   } else {  // back-facing
       result = (info.orientation - degrees + 360) % 360;
   }
   camera.setDisplayOrientation(result);
}

此代码段可用于根据手机的方向设置相机的方向。

【讨论】:

  • ...不要忘记带有预览图像方向的洞穴
  • CaveAt 表示无论您的相机方向设置如何,预览像素都按相机芯片读出顺序(通常是显示屏的右上角)提供
  • 好的。谢谢。一切都很好。但是,当我捕获图像时,图像会以横向模式而不是纵向模式显示。那我该怎么办?
  • @DeeV:您的代码运行良好。但我没有什么问题。当我要捕获图像时,它会保存为横向模式而不是纵向模式。为什么会这样??
猜你喜欢
  • 1970-01-01
  • 2010-10-06
  • 1970-01-01
  • 2018-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多