-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_display_orientation.cs
38 lines (34 loc) · 1.11 KB
/
set_display_orientation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public static void SetCameraDisplayOrientation(Activity activity, Android.Hardware.Camera camera)
{
int cameraId = -1;
CameraInfo info = new CameraInfo();
for (int i = 0; i < 1; i++)
{
if (info.Facing == CameraInfo.CameraFacingBack)
{
cameraId = i;
break;
}
}
GetCameraInfo(cameraId, info);
var rotation = activity.WindowManager.DefaultDisplay.Rotation;
int degrees = 0;
switch (rotation)
{
case SurfaceOrientation.Rotation0: degrees = 0; break;
case SurfaceOrientation.Rotation90: degrees = 90; break;
case SurfaceOrientation.Rotation180: degrees = 180; break;
case SurfaceOrientation.Rotation270: degrees = 270; break;
}
int result;
if (info.Facing == CameraInfo.CameraFacingFront)
{
result = (info.Orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
}
else
{ // back-facing
result = (info.Orientation - degrees + 360) % 360;
}
camera.SetDisplayOrientation(result);
}