Skip to content

Commit

Permalink
Merge pull request #70 from kidpresto92/fixing-android-capture-orient…
Browse files Browse the repository at this point in the history
…ation

Fixes 180-flipped front facing captured pictures for android.
  • Loading branch information
hjam40 authored Jan 9, 2024
2 parents ca5773f + 3d07620 commit edc33b0
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions Camera.MAUI/Platforms/Android/MauiCameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ private bool IsDimensionSwapped()
}
return swappedDimensions;
}

private int GetJpegOrientation()
{
IWindowManager windowManager = context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
Expand All @@ -804,22 +805,14 @@ private int GetJpegOrientation()
int sensorOrientation = (int)(chars.Get(CameraCharacteristics.SensorOrientation) as Java.Lang.Integer);
int deviceOrientation = displayRotation switch
{
SurfaceOrientation.Rotation90 => 0,
SurfaceOrientation.Rotation180 => 270,
SurfaceOrientation.Rotation270 => 180,
_ => 90
SurfaceOrientation.Rotation90 => 90,
SurfaceOrientation.Rotation180 => 180,
SurfaceOrientation.Rotation270 => 270,
_ => 0
};
// Round device orientation to a multiple of 90
//deviceOrientation = (deviceOrientation + 45) / 90 * 90;

// Reverse device orientation for front-facing cameras
//if (cameraView.Camera.Position == CameraPosition.Front) deviceOrientation = -deviceOrientation;

// Calculate desired JPEG orientation relative to camera orientation to make
// the image upright relative to the device orientation
int jpegOrientation = (sensorOrientation + deviceOrientation + 270) % 360;

return jpegOrientation;
var cameraPosition = cameraView.Camera.Position == CameraPosition.Front ? -1 : 1;
return (sensorOrientation - deviceOrientation * cameraPosition + 360) % 360;
}
private class MyCameraStateCallback : CameraDevice.StateCallback
{
Expand Down

0 comments on commit edc33b0

Please sign in to comment.