我如何知道android设备上相机的位置?

问题描述:

我正在构建一个Android应用程序,我使用前置相机进行一些图像处理。我如何知道android设备上相机的位置?

对我来说了解相机的位置非常重要。例如,在三星S3上它位于设备的上部,与Galaxy Note 10一样 - 它位于侧面。

这很重要,所以我可以知道相机预览缓冲区的方向和屏幕本身的方向(我想始终保持UI相对于相机的纵向,即 - 因此相机始终处于打开状态最佳)。

任何想法?

编辑:我可以使用Android 4.0或以上(不需要支持较低版本)

谢谢!

+1

你看过吗? http://*.com/questions/8775872/how-to-detect-where-front-facing-camera-placed-on-device – Andy 2013-04-11 09:38:26

+0

谢谢 - 没有看到它:)似乎'定位'可以被操纵获取正确的信息。 – Roman 2013-04-11 09:41:25

的人说,本身的位置并不重要,你刚才得到的方向等等等等

说,我以前(荣誉为开发它的人)得到了*上这个方法,它的工作原理就像一个魅力。请拨打您的surfaceCreated回拨。

private 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); 
    } 
+0

似乎这只是可能的工作 - 谢谢:) – Roman 2013-04-11 11:13:06

除了来自安卓本身的参考,我不认为有一种方法可以找出其中的摄像头位于设备上: http://developer.android.com/reference/android/graphics/Camera.html