chentao0707 / ZXingProject

精简ZXing项目后只保留扫描功能的代码,去除了ViewfinderView,使用XML布局
MIT License
357 stars 134 forks source link

nexus 5x 相机预览画面反了 #9

Open xianchuangwu opened 7 years ago

xianchuangwu commented 7 years ago

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

magiclonw commented 7 years ago
    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);