[英]Why does System.Drawing.Image.GetPropertyItem behave differently on Windows XP / 2003 compared to Windows 7
I am trying to read the orientation Exif value using System.Drawing.Image.GetPropertyItem(0x0112). 我试图使用System.Drawing.Image.GetPropertyItem(0x0112)读取方向Exif值。
This works fine on Windows 7 and Windows 2008 R2, but fails on Windows XP / Windows Server 2003 (Get a 'Property Cannot Be Found' error). 这在Windows 7和Windows 2008 R2上运行正常,但在Windows XP / Windows Server 2003上失败(获取“无法找到属性”错误)。
On Windows XP / 2003, if I iterate over the available properties (using the PropertyItems property of System.Drawing.Image), I only get 0x5090 (PropertyTagLuminanceTable) and 0x5091 (PropertyTagChrominanceTable) 在Windows XP / 2003上,如果我遍历可用属性(使用System.Drawing.Image的PropertyItems属性),我只得到0x5090(PropertyTagLuminanceTable)和0x5091(PropertyTagChrominanceTable)
With the exact same image in Windows 7 / Windows 2008, I get 18 properties, one of which is 0x0112. 使用Windows 7 / Windows 2008中的完全相同的图像,我得到18个属性,其中一个是0x0112。
I suspect this may be related to the fact that Vista and later versions of Windows have a newer version of GDI+. 我怀疑这可能与Vista和更高版本的Windows有更新版本的GDI +这一事实有关。 Is there any way to get this to work on Windows XP / 2003 without having to write code to read and write Exif data the hard way?
有没有办法让这个在Windows XP / 2003上工作,而不必编写代码来读取和写入Exif数据?
There is a library on NuGet called ExifReader and an accompanying CodeProject article here . 有一个库中的NuGet称为ExifReader和伴随CodeProject上的文章在这里 。
The following code should work for getting the orientation, and you can use the other enumerations of ExifTags to get other pieces of metadata: 以下代码应该用于获取方向,您可以使用ExifTags的其他枚举来获取其他元数据:
object result;
var reader = new ExifReader("c:\\temp\\test\\sample.jpg");
reader.GetTagValue(ExifTags.Orientation, out result);
var orientation = Convert.ToInt32(result);
I have tested this with this image on Windows XP 32-Bit SP3 using .Net 4, and it returned an orientation of 1, which appears to be correct. 我已经使用.Net 4在Windows XP 32-Bit SP3上使用此图像对此进行了测试,并返回了1的方向,这似乎是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.