这是我要做的事。
我有一个摄像头视图用户可以执行一些过程(比例,移动,旋转)
当用户捕获时,我需要将图像放在摄像机框的相同位置,并在摄像机视图上使用应用过程
我这样做如下
mCaptureImage
是相机视图, float x = mCameraView.getX();
float y = mCameraView.getY();
mCaptureImage.setX(x);
mCaptureImage.setY(y);
float angel = mCameraView.getRotation();
mCaptureImage.setRotation(angel);
float scaleX, scaleY;
scaleX = mCameraView.getScaleX();
scaleY = mCameraView.getScaleY();
mCaptureImage.setScaleX(scaleX);
mCaptureImage.setScaleY(scaleY);
是预览图像
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/selfie_move_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<com.otaliastudios.cameraview.CameraView
android:id="@+id/selfie_camera_view"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="gone"
app:cameraCropOutput="true"
app:cameraPlaySounds="false" />
<ImageView
android:id="@+id/selfie_capture_image"
android:layout_width="300dp"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:visibility="gone" />
</FrameLayout>
如果用户没有旋转盒子,一切都还可以
但是,如果用户旋转了盒子,我得到错误的x值,我不知道为什么会发生这种情况并且图像被跳转到未指明的位置
我做了调试,发现旋转视图时x,y值发生了变化
这是 XML
的代码{{1}}
Exmaple about rotation view
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
屏幕的旋转将构成将改变“当前可用屏幕尺寸”的配置更改。为避免这种情况,您必须使用configChanges
属性自行处理配置更改并指定值。
听起来你应该使用“screenSize”和“orientation”值。这会导致您的活动调用onConfigurationChanged()
,而不是重新创建活动。
警告:自行处理配置更改会使使用其他资源变得更加困难,因为系统不会自动为您应用这些资源。当您必须避免因配置更改而重新启动时,此技术应被视为最后的手段,并且不建议用于大多数应用程序。
有关处理配置更改的更多信息:https://developer.android.com/guide/topics/resources/runtime-changes
有关configChange
属性的更多内容:https://developer.android.com/guide/topics/manifest/activity-element#config