2013-04-11 28 views
2

我正在構建一個Android應用程序,我使用前置相機進行一些圖像處理。我如何知道android設備上相機的位置?

對我來說了解相機的位置非常重要。例如,在三星S3上它位於設備的上部,與Galaxy Note 10一樣 - 它位於側面。

這很重要,所以我可以知道相機預覽緩衝區的方向和屏幕本身的方向(我想始終保持UI相對於相機的縱向,即 - 因此相機始終處於打開狀態最佳)。

任何想法?

編輯:我可以使用Android 4.0或以上(不需要支持較低版本)

謝謝!

+1

你看過嗎? http://stackoverflow.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

回答

0

的人說,本身的位置並不重要,你剛纔得到的方向等等等等

說,我以前(榮譽爲開發它的人)得到了StackOverflow上這個方法,它的工作原理就像一個魅力。請撥打您的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

相關問題