Android相机预览旋转

Ah *_*Lam 9 android orientation android-camera

根据Android开发者网站:

在android 2.2之后有功能

"setDisplayOrientation"

调整相机预览旋转.

而且根据Android Developer Site,我们可以找到以下源代码.

android.hardware.Camera.CameraInfo info =
            new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);
    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0 ;
    switch ( rotation ) {
        case Surface.ROTATION_0 : degrees = 0 ; break ;
        case Surface.ROTATION_90 : degrees = 90 ; break ;
        case Surface.ROTATION_180 : degrees = 180 ; break ;
        case Surface.ROTATION_270 : degrees = 270 ; break ;
    }
    int result ;
    if ( info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
        result = ( info.orientation + degrees ) % 360 ;
         result = ( 360 - result ) % 360 ;   // compensate the mirror
    } else {   // back-facing

        result = ( info.orientation - degrees + 360 ) % 360 ;

    }
Run Code Online (Sandbox Code Playgroud)

但是,我无法使用某种设备.如三星Galaxy Y S5360,S5660,YP-G1,YP-G70等

只是机器不工作的一部分,Galaxy Nexus,SII或一些高端设备,它工作正常.

setDisplayOrientation不支持,还是设备固件没有准备好?

PS.所有设备均为Android 2.3.1或更高版本.

救命.

dum*_*ers -3

尝试将相机视图 xml 的方向设置为横向。

  • 如果OP不想风景,他一开始就不会问如何获得肖像,这不是一个真正有用的答案。 (2认同)