简体   繁体   中英

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).

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).

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)

With the exact same image in Windows 7 / Windows 2008, I get 18 properties, one of which is 0x0112.

I suspect this may be related to the fact that Vista and later versions of Windows have a newer version of 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?

There is a library on NuGet called ExifReader and an accompanying CodeProject article here .

The following code should work for getting the orientation, and you can use the other enumerations of ExifTags to get other pieces of metadata:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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