为什么System.Drawing.Image.GetPropertyItem在Windows XP / 2003上的行

本文关键字:2003 XP Windows Drawing System Image GetPropertyItem 为什么 | 更新日期: 2023-09-27 18:37:22

我正在尝试使用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数据?

为什么System.Drawing.Image.GetPropertyItem在Windows XP / 2003上的行

NuGet 上有一个名为 ExifReader 的库,以及随附的 CodeProject 文章。

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

object result;
var reader = new ExifReader("c:''temp''test''sample.jpg");
reader.GetTagValue(ExifTags.Orientation, out result);
var orientation = Convert.ToInt32(result);

我已经使用 .Net 4 在 Windows XP 32-Bit SP3 上使用此图像对此进行了测试,它返回的方向为 1,这似乎是正确的。