2013-02-11 49 views
2

我將手機放在「縱向模式」下,但cameraPreview處於橫向模式(即我看到旋轉90度的東西)。當我將手機放在「橫向模式」下時,預覽很好,處於「橫向模式」,圖像不旋轉。 我無權訪問Camera.setDisplayOrientation(int),因此我無法使用解釋爲here的方法。安卓相機處於橫向模式,但用於縱向模式

我已經試過:

Camera.Parameters p = camera.getParameters(); 
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) 
    { 
     p.set("orientation", "portrait"); 
     p.set("rotation",90); 
    } 
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) 
    {        
     p.set("orientation", "landscape");   
     p.set("rotation", 90); 
    } 
+0

絕對投下的投票,你可以閱讀和幫助。 – morg 2013-02-11 14:32:02

+0

或者,你可以解釋[你曾嘗試過](http://mattgemmell.com/2008/12/08/what-have-you-tried/)?它通常比通用的「我該如何做X?」更好。 – Geobits 2013-02-11 14:38:22

回答

0

行,所以我已經解決這個問題 在 「surfaceCreated」 的方法做

Method rotateMethod; 
    rotateMethod = android.hardware.Camera.class.getMethod("setDisplayOrientation", int.class); 
    rotateMethod.invoke(camera, 90); 

剛過

camera = Camera.open(); 

(CF:Camera is wrong unless keyboard is open)在AndroidManifest

+0

這將方向固定爲縱向模式。如何改變方向時,如何從縱向更改爲橫向? – 2013-08-13 12:26:49

0

嘗試通過設置相機的顯示方向:

Camera camera; 
... 
camera.setDisplayOrientation(90); 

把它放在surfaceCreated(SurfaceHolder持有人)的方法。這在我遇到類似問題時適用於我。

+1

我沒有方法setDisplayOrientation,如上所述。可能是因爲我在8級以前使用API​​ – morg 2013-02-11 14:35:22

+0

您是否有權訪問: Camera.Parameters params = camera.getParameters(); parameters.set(「orientation」,「portrait」); //或風景,您可能想嘗試兩種方法... parameters.setRotation(90); camera.setParameters(parameters); ? 這可能也適用。 – Rockbag 2013-02-11 14:44:31

+0

試過了,沒有改變任何東西:/ – morg 2013-02-11 14:46:47

0

添加代碼。工作區項目中的xml Activity。

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:screenOrientation="landscape" 
     android:theme="@android:style/Theme.NoTitleBar" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 
相關問題