gpt4 book ai didi

java - 为相机应用程序获得相同的方向角

转载 作者:行者123 更新时间:2023-11-30 12:07:57 33 4
gpt4 key购买 nike

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

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

用于 AndroidMainfest 中的 Activity 。现在我正在尝试确定方向,它总是呈 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;
}

最佳答案

也许你错过了电话

camera.setDisplayOrientation(result);

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

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

关于java - 为相机应用程序获得相同的方向角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54540516/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com