我在做我的图片不是在正确的方向保存相机app.In。我设置
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
在AndroidMainfest活动。现在我想获得它的方向始终给予90度。我想用screenOrientation =纵向移动方向。如果我使用GET定向这段代码: -
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);
后确定度和面向相机补偿前面。
但是,这仅影响的方式你的相机预览显示在屏幕上。录像或预览回调仍然提供相机架在它们的自然方向。