【问题标题】:Change orientation of camera preview in android depending on the orentation of the layout根据布局的方向更改android中相机预览的方向
【发布时间】:2013-04-11 10:43:43
【问题描述】:

我在surfaceView 中显示Camera 预览。在表面回调中,我在 surfaceChanged 函数中有这段代码:

                if(getResources().getConfiguration().orientation== getResources().getConfiguration().ORIENTATION_LANDSCAPE)
                    camera.setDisplayOrientation(0);
                else
                    camera.setDisplayOrientation(90);

这工作正常,它可以纵向旋转相机。但是,当我将平板电脑转动 180 度之间进行切换时,预览的方向是错误的。是否有一个属性可以决定平板电脑是向上还是向下,以便我可以记录改变方向。

【问题讨论】:

    标签: android orientation android-camera


    【解决方案1】:

    你可以使用getRotation()

    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    int orientation = display.getRotation();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多