0

I need to read any image's orientation in .net. I am trying to read this information through extracting orientation property from Exif data.

 public enum ExifOrientations
    {
        Unknown = 0,
        TopLeft = 1,
        TopRight = 2,
        BottomRight = 3,
        BottomLeft = 4,
        LeftTop = 5,
        RightTop = 6,
        RightBottom = 7,
        LeftBottom = 8,
    }

    // Return the image's orientation.
    public static ExifOrientations ImageOrientation(Image img)
    {
        const int OrientationId = 0x0112;

        // Get the index of the orientation property.
        int orientation_index =
            Array.IndexOf(img.PropertyIdList, OrientationId);

        // If there is no such property, return Unknown.
        if (orientation_index < 0) return ExifOrientations.Unknown;

        var orientationValue = img.GetPropertyItem(OrientationId).Value[0]; 
        // Return the orientation value.
        return (ExifOrientations)
            img.GetPropertyItem(OrientationId).Value[0];
    }

But I found many images don't have EXIF data for orientation, in that case, what is the best way to get an image's orientation.

enter image description here

This image doesn't have any orientation data. But below picture I think gives wrong orientation data or I misunderstood.

enter image description here

How is this image's orientation can be "TopLeft" as it's determined by the above code?

I need to know is there any other way of getting the image's orientation data if EXIF data doesn't exist.

ADJ
  • 21
  • 7

1 Answers1

1

There's not really any perfect way to detect orientation without EXIF data. Systems that do this either use the dimensions of the image or detect content in the image.

This answer has a good breakdown on the different option and And this answer has a great JavaScript function for detecting the orientation.

Patrick
  • 334
  • 2
  • 7