【问题标题】:Android camera is in landscape but used in portrait modeAndroid 相机处于横向但在纵向模式下使用
【发布时间】:2013-02-11 14:26:59
【问题描述】:

我将手机置于“纵向模式”,但 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);
    }

【问题讨论】:

  • 反对投票,您可以阅读并提供帮助。
  • 或者,你可以解释一下what you have tried?它通常比通用的“我该怎么做 X?”效果更好

标签: android camera


【解决方案1】:

尝试使用以下方法设置相机的显示方向:

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

放到surfaceCreated(SurfaceHolder holder)方法中。当我遇到类似问题时,这对我有用。

【讨论】:

  • 我没有 setDisplayOrientation 方法,如前所述。可能是因为我使用 8 级之前的 API
  • 您是否有权访问:Camera.Parameters params = camera.getParameters(); parameters.set("方向", "肖像"); // 或风景,你可能想同时尝试... parameters.setRotation(90); camera.setParameters(参数); ?这可能也有效。
  • 也试过了,没有任何改变:/
  • 你试过两个方向吗? params.set("orientation" , "landscape") 和 params.set("orientation" , "portrait")?你应该玩一下这些。
  • 是的,我都试过了,但还是一样。也许我没有写在正确的地方? (我写在surfaceCreated中)
【解决方案2】:

好的,我已经解决了问题 在“surfaceCreated”方法中做

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

紧接着

camera = Camera.open();

(参见:Camera is wrong unless keyboard is open

【讨论】:

  • 这将方向固定为纵向模式。改变方向时如何从纵向更改为横向?
【解决方案3】:

在您的工作区项目的 AndroidManifest.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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    相关资源
    最近更新 更多