From 9db0ddd15c1aa690a5652abc110284c9637bdf12 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Fri, 15 Sep 2023 13:10:41 -0400 Subject: [PATCH] actually rotate the image in output --- Photo.cs | 3 +++ Program.cs | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Photo.cs b/Photo.cs index 80e6fd2..fa4eb91 100644 --- a/Photo.cs +++ b/Photo.cs @@ -219,6 +219,9 @@ public class Photo { Console.WriteLine($"{Filename} => {jpgOut}"); await image.SaveAsync(jpgOut, new JpegEncoder() { Quality = 100 }); + if (Math.Abs(RotationDegrees) > 0.001) { + image.Mutate(x => x.Rotate(RotationDegrees)); + } if (CropRectangle != Rectangle.Empty) { image.Mutate(x => x.Crop(CropRectangle)); } diff --git a/Program.cs b/Program.cs index af9a04a..9b2672a 100644 --- a/Program.cs +++ b/Program.cs @@ -265,6 +265,10 @@ public class StraightenTool : ITool { } public ToolStatus HandleInput(KeyboardState input, MouseState mouse, Transform transform, Game game, Photo photo, UiGeometry geometry) { + if (input.IsKeyPressed(Keys.D0)) { + photo.RotationDegrees = 0; + } + if (input.IsKeyPressed(Keys.Left)) { photo.RotationDegrees += .1f; } @@ -700,6 +704,7 @@ public class Game : GameWindow { } // Handle tool switching. + // FIXME: prevent photo switching when tools other than ViewTool are active? if (photos[photoIndex] != previousPhoto) { activeTool = viewTool; } @@ -708,7 +713,7 @@ public class Game : GameWindow { if (input.IsKeyPressed(Keys.C)) { activeTool = new CropTool(photos[photoIndex]); } - if (input.IsKeyPressed(Keys.S)) { + if (input.IsKeyPressed(Keys.X)) { activeTool = new StraightenTool(photos[photoIndex]); } } @@ -789,10 +794,10 @@ public class Game : GameWindow { // Load photos from a directory. // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\"); // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\"); - string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\09\06\jpg"); + // string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\09\06\jpg"); // string[] files = Directory.GetFiles(@"G:\DCIM\100EOSR6\"); // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\totte-output\2023\08\03"); - // string[] files = Directory.GetFiles(@"c:\users\colin\desktop\export"); + string[] files = Directory.GetFiles(@"c:\users\colin\desktop\export"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Pictures\photos\2018\06\23"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\Germany all\104D7000"); // string[] files = Directory.GetFiles(@"C:\Users\colin\Desktop\many-birds\");