【问题标题】:got same orientation angle for camera app相机应用程序的方向角度相同
【发布时间】:2019-02-05 18:06:50
【问题描述】:

我正在制作相机应用程序。因为我的图像没有以正确的方向保存。 我设置了

         <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait">

用于 AndroidMainfest 中的活动。 现在我正在尝试定位它总是给出 90 度。 我想通过 screenOrientation =portrait 获得移动方向。 如果我使用此代码获取方向:-

public int setPhotoOrientation(Activity activity, int cameraId) {
    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;
    // do something for phones running an SDK before lollipop
    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;
    }

    return result;
}

【问题讨论】:

    标签: java android android-camera screen-orientation


    【解决方案1】:

    也许你错过了电话

    camera.setDisplayOrientation(result);
    

    在确定度数并补偿前置摄像头之后。

    但这只会影响相机预览在屏幕上的显示方式。视频录制或预览回调仍以自然方向传送相机帧。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      • 2016-02-17
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      相关资源
      最近更新 更多