Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read the EXIF data from an image taken with an Apple iPhone

Tags:

c#

iphone

exif

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

I need the GPS related data.

PS: I know how to read EXIF except image taken with an Apple iPhone

like image 936
zunyite Avatar asked Jan 30 '10 21:01

zunyite


2 Answers

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

It supports over 150 known EXIF tags including 32 GPS related ones. Getting the latitude and longitude is as easy as:

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

It even has a neat little demo application with an interactive visualization of the binary data: ExifLibrary demo

like image 155
Nathan Baulch Avatar answered Sep 28 '22 16:09

Nathan Baulch


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, along with a tonne of other metadata types and file types.

Here are examples of the output from an iPhone 4, iPhone 5 and an iPhone 6.

It's 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 to print out every single discovered 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);
like image 35
Drew Noakes Avatar answered Sep 28 '22 17:09

Drew Noakes