c# - 与 Windows 7 相比,为什么 System.Drawing.Image.GetPropertyItem 在 Windows XP/2003 上的行为不同

标签 c# system.drawing

我正在尝试使用 System.Drawing.Image.GetPropertyItem(0x0112) 读取方向 Exif 值。

这在 Windows 7 和 Windows 2008 R2 上工作正常,但在 Windows XP/Windows Server 2003 上失败(出现“无法找到属性”错误)。

在 Windows XP/2003 上,如果我遍历可用属性(使用 System.Drawing.Image 的 PropertyItems 属性),我只会得到 0x5090 (PropertyTagLuminanceTable) 和 0x5091 (PropertyTagChrominanceTable)

在 Windows 7/Windows 2008 中使用完全相同的图像,我得到 18 个属性,其中之一是 0x0112。

我怀疑这可能与 Vista 和更高版本的 Windows 具有更新版本的 GDI+ 有关。有什么方法可以让它在 Windows XP/2003 上运行,而无需编写代码来以困难的方式读写 Exif 数据?

最佳答案

NuGet 上有一个名为 ExifReader 的库和随附的 CodeProject 文章 here .

以下代码应该可以获取方向,您可以使用 ExifTags 的其他枚举来获取其他元数据:

object result;

var reader = new ExifReader("c:\\temp\\test\\sample.jpg");
reader.GetTagValue(ExifTags.Orientation, out result);

var orientation = Convert.ToInt32(result);

我用 this image 测试过这个在使用 .Net 4 的 Windows XP 32 位 SP3 上,它返回方向 1,这似乎是正确的。

关于c# - 与 Windows 7 相比,为什么 System.Drawing.Image.GetPropertyItem 在 Windows XP/2003 上的行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19660123/

相关文章:

gdi+ - Graphics.MeasureCharacterRanges 给出错误的尺寸计算

c# - 使用绘制事件移动对象

c# - ExecuteNonQuery 不更新输出参数

c#:在 my.settings 中存储大量数据

C# 从本地目录打开程序

c# - 检测像素或其周围区域的亮度

c# - 如何将表单中的面板保存为图片?

c# - 使用 Graphics.DrawString 时动态调整字体大小以适应空间

c# - 将 orderby、Skip() 和 Take() 与 LINQ 一起使用时出现重复行

c# - 如何从跨域 API 获取数据