INT:對角以度數順時針旋轉。支持的角度是0,90,180和270度。
對於MediaRecorder,您可以從下面參考參考。
你需要獲得當前攝像機的方向,然後添加基於前置攝像頭和後置攝像頭的設置方向的邏輯:
下面是camera1API
Camera.CameraInfo camera_info = new Camera.CameraInfo()
int camera_orientation = camera_info.orientation;
下面是對於camera2API
CameraCharacteristics characteristics;
CameraManager manager = (CameraManager)getSystemService(Context.CAMERA_SERVICE);
characteristics = manager.getCameraCharacteristics(cameraIdS);
int camera_orientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
下面是兩個camera1API和camera2API
的INT camera_orientation攝像機圖像的常見。該值是攝像機圖像需要順時針旋轉的角度,以便以正確的方向正確顯示在顯示器上。它應該是0,90,180,270。 例如,假設設備的屏幕自然很高。背面照相機傳感器安裝在橫向上。你正在看屏幕。如果相機傳感器的頂部與自然方向的屏幕右邊緣對齊,則該值應爲90.如果前置攝像頭傳感器的頂部與屏幕右邊對齊,則值應爲是270
private int getDeviceDefaultOrientation() {
WindowManager windowManager = (WindowManager)this.getContext().getSystemService(Context.WINDOW_SERVICE);
Configuration config = getResources().getConfiguration();
int rotation = windowManager.getDefaultDisplay().getRotation();
if(((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
config.orientation == Configuration.ORIENTATION_LANDSCAPE)
|| ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
return Configuration.ORIENTATION_LANDSCAPE;
}
else {
return Configuration.ORIENTATION_PORTRAIT;
}
}
設置方向爲橫向
int device_orientation = getDeviceDefaultOrientation();
int result;
if (device_orientation == Configuration.ORIENTATION_PORTRAIT) {
// should be equivalent to onOrientationChanged(270)
if (camera_controller.isFrontFacing()) {
result = (camera_orientation + 90) % 360;
} else {
result = (camera_orientation + 270) % 360;
}
} else {
// should be equivalent to onOrientationChanged(0)
result = camera_orientation;
}
設定方向爲縱向
int device_orientation = getDeviceDefaultOrientation();
int result;
if (device_orientation == Configuration.ORIENTATION_PORTRAIT) {
// should be equivalent to onOrientationChanged(0)
result = camera_orientation;
} else {
// should be equivalent to onOrientationChanged(90)
if (camera_controller.isFrontFacing()) {
result = (camera_orientation + 270) % 360;
} else {
result = (camera_orientation + 90) % 360;
}
}
請發表您迄今嘗試過的內容。發佈您的代碼而不是鏈接。 –