【发布时间】: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