繁体   English   中英

为什么System.Drawing.Image.GetPropertyItem在Windows XP / 2003上的行为与Windows 7相比有所不同

[英]Why does System.Drawing.Image.GetPropertyItem behave differently on Windows XP / 2003 compared to Windows 7

我试图使用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上的文章在这里

以下代码应该用于获取方向,您可以使用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的方向,这似乎是正确的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM