我在网上找了很多代码,还有书上的代码,实现摄像头。但是当我打开程序时,手机横着时,屏幕中看到的影像是正常的,当把手机竖起来时,程序自动旋转,影像也被逆时针旋转了90度。请问,如何才能使手机横着和竖着时,看到的均为正常的影像。谢谢

解决方案 »

  1.   

    在manifest.xml内activity里面加
    android:screenOrientation="portrait"
    android:configChanges="orientation|keyboardHidden"
      

  2.   

    楼主是不是有gsensor,而这个gsensor定义的角度正好与摄像头的角度相差90度?
      

  3.   

    我现在是希望在竖屏模式下做开发,但是摄像头在竖屏模式时会偏转90度。
    使用如下语句后
    parameters.set("orientation", "portrait");
    有的手机上摄像头不再偏转,如华为手机,nexus one 2.1都是正常的。
    但是在nexus one 2.2 和mile stone上摄像头依然是偏转的。
      

  4.   

    会不会nexus one 2.2 和mile stone这两款手机定义portrait和landscape的方向与华为的不同呢?
      

  5.   

    呵呵,不然怎么就这两款不同呢,你可以弄一个landscape的APK进去跑一下,就知道了。
      

  6.   

    问题解决了...
    // 旋转90°
    if (Integer.parseInt(Build.VERSION.SDK) >= 8) {// 判断系统版本是否大于等于2.2
    setDisplayOrientation(mCamera, 90);// 旋转90°,前提是当前页portrait,纵向
    } else {// 系统版本在2.2以下的采用下面的方式旋转
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
    params.set("orientation", "portrait");
    params.set("rotation", 90);
    }
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
    params.set("orientation", "landscape");
    params.set("rotation", 90);
    }
    }
         <activity android:name=".TakePictureActivity"
              android:configChanges="keyboardHidden|orientation"
      android:screenOrientation="portrait"
            />