Fotoapparat:为什么横向CameraView在人像模式下拍摄



我已经将Fotoapparat库嵌入到我的应用程序中。为了用一只手操作整个应用程序,我正试图使CameraView处于人像模式父母约束布局。正如您在下面的屏幕截图中看到的,CameraView本身是横向的,但整个Fragment的父ConstraintLayout是纵向模式,因此用户可以单手操作应用程序:一只手抓住风景正如你所看到的,CameraView是在lanscape中建模的,当然这意味着质量有点损失。

然后我捕获一张图像,并在下一个片段中显示捕获的图像。。正如您所看到的,捕获的图像现在是人像模式:人像中显示的捕获图像

正如你所看到的不同,我捕捉到的智能手机塑料帽也在风景中。左角和右角非常合脚。但图像的顶部和底部的像素明显多于前一片段预览中显示的像素。

我创建Fotoapparart对象,如:

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.0Java SDK 8安卓工作室3.2

我做错了什么

或者用其他词:

如何在手持相机/智能手机人像时拍摄横向裁剪

我认为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);
}

最新更新