ZXingProject icon indicating copy to clipboard operation
ZXingProject copied to clipboard

nexus 5x 相机预览画面反了

Open xianchuangwu opened this issue 8 years ago • 1 comments

我设置theCamera.setDisplayOrientation(90);也不起作用,不知道为什么

xianchuangwu avatar Feb 21 '17 10:02 xianchuangwu

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

magiclonw avatar Oct 20 '17 06:10 magiclonw