How can I read EXIF ​​data from an image taken using an Apple iPhone

How can I read EXIF ​​data from an image taken using an Apple iPhone using C #?

I need GPS related data.

PS: I know how to read EXIF, except for the image made using the Apple iPhone

+5
source share
3 answers

I would recommend you take a look at the exiflibrary project in Google Code and its associated ExifLibrary for.NET in the article on code project.

It supports over 150 well-known EXIF ​​tags, including 32 related to GPS. Getting latitude and longitude is as simple as:

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

It even has a small little demo application with interactive binary data visualization: ExifLibrary demo

+8
source

If you upload an image using:

 Image image = Image.FromFile(imageName); 

EXIF values ​​are read into the PropertyItems array in the image.

I found code to interpret these tags as EXIF ​​data. I can’t remember where I got it from now, but I found a copy here . I do not think that the code in its current form reads geolocation codes, but this page claims to have a list of all EXIF ​​tags, so you can extend this code.

The id tag 0x8825 is GPSInfo. GPS tags are listed on this page.

+2
source

The MetadataExtractor library has been available for Java since 2002 and is now fully supported for .NET. It supports Exif GPS data from JPEG files, as well as tons of other types and types of metadata files.

The following are examples from iPhone 4 , iPhone 5, and iPhone 6 .

Available via NuGet:

 PM> Install-Package MetadataExtractor 

Then, to access the GPS location, use the following code:

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

Or print each detected value:

 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); 
+2
source

All Articles