5

如何从使用 C#的Apple iPhone拍摄的图像中读取 EXIF 数据?

我需要 GPS 相关数据。

PS:除了用Apple iPhone拍摄的图像外,我知道如何读取 EXIF

4

3 回答 3

8

我建议您查看 Google Code 上的exiflibrary项目及其相关的ExifLibrary for .NET文章 Code Project。

它支持超过 150 个已知的 EXIF 标签,包括 32 个与 GPS 相关的标签。获取纬度和经度很简单:

var exif = ExifFile.Read(fileName);
Console.WriteLine(exif.Properties[ExifTag.GPSLatitude]);
Console.WriteLine(exif.Properties[ExifTag.GPSLongitude]);

它甚至有一个简洁的小演示应用程序,带有二进制数据的交互式可视化: ExifLibrary 演示

于 2010-01-30T23:20:30.080 回答
3

MetadataExtractor库自 2002 年起可用于 Java,现在完全支持 .NET 。它支持来自 JPEG 文件的 Exif GPS 数据,以及大量其他元数据类型和文件类型。

以下是iPhone 4iPhone 5iPhone 6的输出示例。

它可以通过 NuGet 获得:

PM> Install-Package MetadataExtractor

然后,要访问 GPS 位置,请使用以下代码:

var directories = ImageMetadataReader.ReadMetadata(jpegFilePath);

var gps = directories.OfType<GpsDirectory>().FirstOrDefault();

var location = gps?.GetGeoLocation();

if (location != null)
    Console.WriteLine("Lat {0} Lng {1}", location.Latitude, location.Longitude);

或者打印出每一个发现的值:

var lines = from directory in directories
            from tag in directory.Tags
            select $"{directory.Name}: {tag.TagName} = {tag.Description}";

foreach (var line in lines)
    Console.WriteLine(line);
于 2015-08-09T21:49:28.943 回答
2

If you load an image using:

Image image = Image.FromFile(imageName);

The EXIF values are read into the PropertyItems array on the image.

I found some code for interpreting these tags as EXIF data. I can't remember where I got it from now but I've found a copy here. I don't think that the code as it stands reads the geolocation codes, but this page claims to have a list of all EXIF tags, so you could extend this code.

Tag id 0x8825 is the GPSInfo. The GPS tags are enumerated on this page

于 2010-01-30T21:33:30.117 回答