【问题标题】:How to read any image's orientation information if EXIF data doesn't exist?如果 EXIF 数据不存在,如何读取任何图像的方向信息?
【发布时间】:2019-07-19 01:59:51
【问题描述】:

我需要在 .net 中读取任何图像的方向。我正在尝试通过从 Exif 数据中提取方向属性来读取此信息。

 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];
    }

但我发现许多图像没有用于方向的 EXIF 数据,在这种情况下,获取图像方向的最佳方法是什么。

此图片没有任何方向数据。但我认为下面的图片给出了错误的方向数据或者我误解了。

这个图像的方向如何可以是“TopLeft”,因为它是由上面的代码确定的?

如果 EXIF 数据不存在,我需要知道是否有其他方法可以获取图像的方向数据。

【问题讨论】:

标签: c# asp.net .net asp.net-mvc


【解决方案1】:

在没有 EXIF 数据的情况下,没有任何完美的方法来检测方向。执行此操作的系统要么使用图像的尺寸,要么检测图像中的内容。

This answer has a good breakdown on the different optionAnd this answer has a great JavaScript function for detecting the orientation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-19
    • 2011-06-13
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多