handle all 8 Exif orientations

This commit is contained in:
Colin McMillen 2023-07-25 14:48:02 -04:00
parent c461d55101
commit 4f667f2400

View File

@ -386,12 +386,20 @@ public static class Util {
// https://sirv.com/help/articles/rotate-photos-to-be-upright/ // https://sirv.com/help/articles/rotate-photos-to-be-upright/
public static void RotateImageFromExif(Image<Rgba32> image, ushort orientation) { public static void RotateImageFromExif(Image<Rgba32> image, ushort orientation) {
if (orientation == 1) { if (orientation <= 1) {
return; return;
} }
if (orientation == 8) { var operations = new Dictionary<ushort, (RotateMode, FlipMode)> {
image.Mutate(x => x.RotateFlip(RotateMode.Rotate270, FlipMode.None)); { 2, (RotateMode.None, FlipMode.Horizontal) },
} { 3, (RotateMode.Rotate180, FlipMode.None) },
{ 4, (RotateMode.Rotate180, FlipMode.Horizontal) },
{ 5, (RotateMode.Rotate90, FlipMode.Vertical) },
{ 6, (RotateMode.Rotate90, FlipMode.None) },
{ 7, (RotateMode.Rotate270, FlipMode.Vertical) },
{ 8, (RotateMode.Rotate270, FlipMode.None) },
};
var (rotate, flip) = operations[orientation];
image.Mutate(x => x.RotateFlip(rotate, flip));
} }
public static Texture RenderText(string text) { public static Texture RenderText(string text) {