Fotoapparat:为什么横向 CameraView 在纵向模式下拍摄?

Fotoapparat: Why does landscape CameraView captures in portrait mode?

我已经将 Fotoapparat 库应用到我的应用程序中。为了用一只手操作整个应用程序,我试图使 CameraView 处于纵向模式 parents ConstraintLayout。在下面的截图中可以看到,CameraView本身是横向的,但是整个Fragment的parentConstraintLayout是纵向模式,这样用户就可以单手操作app: One hand hold to capture landscape 如您所见,CameraView 是横向建模的,当然这意味着质量会有所下降。

然后我截取一张图片,并在下一个片段中显示截取的图像。如您所见,截取的图像现在是纵向模式: Captured images shown in portrait

如您所见,我还横向拍摄了智能手机的塑料盖。左右角非常吻合。但是图像顶部和底部的像素比上一个片段的预览中显示的像素明显多。

我创建 Fotoapparart object 如下:

fotoapparat = Fotoapparat
                .with(activity)
                .into(cameraView)
                .focusView(focusView)
                .sensorSensitivity(highestSensorSensitivity())
                .focusMode(firstAvailable(
                        FocusModeSelectorsKt.continuousFocusPicture(),
                        FocusModeSelectorsKt.autoFocus()))
                .lensPosition(back())
                .build();

我的布局是这样的:

<io.fotoapparat.view.CameraView
    android:id="@+id/myapp_camera_view"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="@dimen/myapp_border_margin"
    android:layout_marginEnd="@dimen/myapp_border_margin"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintDimensionRatio="1.778"
    app:layout_constraintBottom_toTopOf="@+id/myapp_border"
    app:layout_constraintTop_toBottomOf="@id/myapp_holder"
    app:layout_constraintVertical_bias="0.5">

    <io.fotoapparat.view.FocusView
        android:id="@+id/myapp_focus_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    />

</io.fotoapparat.view.CameraView>

这里我有拍照功能:

void takePicture(final boolean fotoapparatIsStopped) {
    if (!fotoapparatIsStopped) {
        PhotoResult photoResult = fotoapparat.takePicture();

        photoResult.toBitmap()
        .whenDone(new WhenDoneListener<BitmapPhoto>() {
            @Override
            public void whenDone(@Nullable BitmapPhoto photo) {
                this.bitmapPhoto = photo;
            }
        });
    }
}

版本:Fotoapparat 2.4.0 Java SDK 8 Android Studio 3.2

我哪里错了?

或者换句话说:

如何在拿着 camera/smartphone 人像的同时拍摄风景作物?

我认为 Fotoapparat 不提供开箱即用的此功能。您可能必须通过旋转位图本身来手动执行此操作:

// rotate Bitmap by means of rotation matrix    
public void whenDone(@Nullable BitmapPhoto photo) {
    Matrix rotationMatrix = new Matrix();
    rotationMatrix.postRotate(phi); // int phi is the angle, here 90

    Bitmap landscapeBitmap = Bitmap.createBitmap(photo.bitmap, 0, 0, photo.bitmap.getWidth(), photo.bitmap.getHeight(), rotationMatrix, true);
    this.bitmapPhoto = new BitmapPhoto(landscapeBitmap, 0);
}