【问题标题】:Using Camera in Portrait Orientation纵向使用相机
【发布时间】:2010-09-11 14:52:38
【问题描述】:

我正在尝试开发一个使用相机的应用程序。到目前为止,它运行良好,除了我无法将方向强制为“纵向”。如果我将所有活动强制为“横向”似乎效果很好,因为相机预览似乎适合横向。

是否可以在纵向模式下使用相机?

【问题讨论】:

  • 在 G1 设备或非 g1 设备上,因为 g1s 的方向显示相机预览错误
  • 嗨 Fred,我使用的是三星 Galaxy S...

标签: android


【解决方案1】:

Android 设备 v2.2 及更高版本包含用于将显示旋转为纵向的 API。低于 2.2 的设备仅适用于横向。最好的办法是检测设备是否为 2.2 并旋转 90 度。 2.2 以下的设备回退到横向。好消息是大多数 Android 设备都运行 2.2 及更高版本。

在此处查看我的答案以获取更多信息:

Camera is wrong unless keyboard is open

【讨论】:

  • 知识渊博,我可以看到很多人遇到这个问题而没有找到解决方案。
  • 您可能希望在您的应用中添加一个设置以允许用户强制横向。我已经测试过,似乎无法在某些设备上强制人像。到目前为止,我知道这些设备不能设置为纵向,即使是 Android 2.2+:“GT-S6102”、“GT-S5360”、“GT-S5660”、“YP-G1”、“YP-G70”。我敢肯定还有更多:/
【解决方案2】:
public void surfaceCreated(SurfaceHolder holder)
{
// The Surface has been created, acquire the camera and tell it where to draw.
mCamera = Camera.open();

Parameters params = mCamera.getParameters();

if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
{
params.set("orientation", "portrait");
mCamera.setDisplayOrientation(90);
}

try
{
mCamera.setPreviewDisplay(holder);
}
catch (IOException exception)
{
mCamera.release();
mCamera = null;
}

}

【讨论】:

    【解决方案3】:

    编辑:当我回答这个问题时,我正处于 Adob​​e AIR for Android 开发的过程中,回过头来看,我意识到这个问题与 Adob​​e AIR 无关。

    Adobe 说:

    在可以更改屏幕方向的设备(例如手机)上,附加到摄像头的 Video 对象只会以横向显示垂直视频。因此,移动应用在显示视频时应使用横向,并且不应自动旋转。

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html

    如果你真的想在纵向模式下使用相机,我的建议是旋转视频对象。

    以下是一些示例代码,可将视频对象 (_video) 旋转角度(以度为单位)(源代码是从 stackoverflow 的其他地方提取的):

            var matrix:Matrix = _video.transform.matrix; 
            var rect:Rectangle = _video.getBounds(this); 
            matrix.translate(- (rect.left + (rect.width/2)), - (rect.top + (rect.height/2))); 
            matrix.rotate((angle/180)*Math.PI); 
            matrix.translate(rect.left + (rect.width/2), rect.top + (rect.height/2));
            _video.transform.matrix = matrix;
    

    【讨论】:

      猜你喜欢
      • 2014-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多