【发布时间】:2018-11-04 08:20:18
【问题描述】:
我已经在我的应用程序中实现了 Fotoapparat 库。为了用一只手操作整个应用程序,我试图让 CameraView 在纵向模式下成为父 ConstraintLayout。如下截图所示,CameraView本身是横向的,而整个Fragment的父ConstraintLayout是纵向模式,这样用户就可以单手操作app了: One hand hold to capture landscape 如您所见,CameraView 是在 lanscape 中建模的,这当然意味着质量会有所下降。
然后我捕捉一张图像并在下一个片段中显示捕捉到的图像。如您所见,捕捉到的图像现在是纵向模式: Captured images shown in portrait
正如您所看到的不同,我还以横向拍摄了智能手机塑料盖。左右角非常适合。但是图像顶部和底部的像素明显多于上一个片段的预览中显示的像素。
我创建了 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>
这里我有 takePhoto 功能:
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
我哪里错了?
或者换句话说:
如何在手持相机/智能手机人像的同时捕捉横向裁剪?
【问题讨论】:
标签: android android-layout android-camera camera-api camera-view