picoe / Eto

Cross platform GUI framework for desktop and mobile applications in .NET
Other
3.57k stars 325 forks source link

Accessing Exif image information #2465

Closed Serg-Norseman closed 12 months ago

Serg-Norseman commented 1 year ago

What is sorely lacking is the ability to "normalize" photos available at the top level of Eto.Forms. To be able to write something like this:

        private const int ExifOrientationTagId = 274;

        public static void NormalizeOrientation(Image image)
        {
            if (image == null || Array.IndexOf(image.PropertyIdList, ExifOrientationTagId) < 0) return;

            int orientation = image.GetPropertyItem(ExifOrientationTagId).Value[0];
            if (orientation >= 1 && orientation <= 8) {
                switch (orientation) {
                    case 2:
                        image.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        break;
                    case 3:
                        image.RotateFlip(RotateFlipType.Rotate180FlipNone);
                        break;
                    case 4:
                        image.RotateFlip(RotateFlipType.Rotate180FlipX);
                        break;
                    case 5:
                        image.RotateFlip(RotateFlipType.Rotate90FlipX);
                        break;
                    case 6:
                        image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        break;
                    case 7:
                        image.RotateFlip(RotateFlipType.Rotate270FlipX);
                        break;
                    case 8:
                        image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                        break;
                }

                image.RemovePropertyItem(ExifOrientationTagId);
            }
        }
Serg-Norseman commented 12 months ago

Solved using ImageSharp.