Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从苹果iPhone拍摄的图像中读取EXIF数据_C#_Iphone_Exif - Fatal编程技术网

C# 如何从苹果iPhone拍摄的图像中读取EXIF数据

C# 如何从苹果iPhone拍摄的图像中读取EXIF数据,c#,iphone,exif,C#,Iphone,Exif,如何使用C#从苹果iPhone拍摄的图像中读取EXIF数据 我需要GPS相关数据 PS:我知道如何读取EXIF,但如果您使用以下方式加载图像,则使用苹果iPhone拍摄的图像除外: Image image = Image.FromFile(imageName); EXIF值被读入图像上的PropertyItems数组 我找到了一些将这些标记解释为EXIF数据的代码。我不记得从哪里弄来的,但我找到了一份。我不认为现在的代码可以读取地理位置代码,但是声明有一个所有EXIF标记的列表,因此您可以扩展

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

我需要GPS相关数据


PS:我知道如何读取EXIF,但如果您使用以下方式加载图像,则使用苹果iPhone拍摄的图像除外:

Image image = Image.FromFile(imageName);
EXIF值被读入图像上的
PropertyItems
数组

我找到了一些将这些标记解释为EXIF数据的代码。我不记得从哪里弄来的,但我找到了一份。我不认为现在的代码可以读取地理位置代码,但是声明有一个所有EXIF标记的列表,因此您可以扩展此代码


标记id
0x8825
是GPSInfo。GPS标签列举在

上,我建议您查看Google代码项目及其相关的代码项目文章

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

var exif = ExifFile.Read(fileName);
Console.WriteLine(exif.Properties[ExifTag.GPSLatitude]);
Console.WriteLine(exif.Properties[ExifTag.GPSLongitude]);
它甚至有一个简洁的小演示应用程序,带有二进制数据的交互式可视化:

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

以下是和的输出示例

可通过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);

我尝试了这个演示,但它无法读取用“苹果iPhone”拍摄的图像的EXIF。我认为Code项目的演示是一个旧版本。您应该尝试根据谷歌代码的最新版本(v0.9)编译演示应用程序。v0.9无法从IPhone图像中提取GPS EXIF数据。您是否解决了此问题?我也有同样的问题。Apple不在PropertyTagGpsLatitude=0x0002和PropertyTagGpsLatitude=0x0004中保存:(
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);