Introduction
This tip shows you how to read Exif coordinates from image for Windows phone 8.
I have gone round and round trying to find a plug and play solution for reading exif information from every corner of the internet and by reading the few books I have access to without much success.
I decided to come up with my own plug and play version of an exif reader, thanks to the C# implementation of an EXIF Library available on CodeProject, by Tim Heuer(Good Man!). Works well for both Windows Phone 7 and 8.
So I combined the foundational work by Igor Ralic and Colin Eberhardt to create this simple class for accessing geocode information from images.
So accessing Exif data has never been a piece of cake with this awesome one liner call to the JpegInfo
class.
JpegInfo info = ExifLib.ExifReader.ReadJpeg(e.ChosenPhoto, e.OriginalFileName);
The JpegInfo
provides direct access to the exif data which you can create your own objects for storing the data and use how you want! I know you are crazy with the blah blah blah – so here is the code:
void task_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
photoLoaded = true;
JpegInfo info = ExifLib.ExifReader.ReadJpeg(e.ChosenPhoto, e.OriginalFileName);
var img = new BitmapImage();
img.SetSource(e.ChosenPhoto);
loadedImg.Source = img;
ReadExif(info);
}
}
private static double DecodeLatitude(JpegInfo info)
{
double degrees = ToDegrees(info.GpsLatitude);
return info.GpsLatitudeRef == ExifGpsLatitudeRef.North ? degrees : -degrees;
}
private static double DecodeLongitude(JpegInfo info)
{
double degrees = ToDegrees(info.GpsLongitude);
return info.GpsLongitudeRef == ExifGpsLongitudeRef.East ? degrees : -degrees;
}
public static double ToDegrees(double[] coord)
{
return coord [0] + coord [1] / 60.0 + coord [2] / (60.0 * 60.0);
}
private void ReadExif(JpegInfo info)
{
var Lat = 0.0;
var Long = 0.0;
if (info.GpsLatitude.First() != 0.0)
{
Lat = DecodeLatitude(info);
Long = DecodeLongitude(info);
}
}
Something this like has never been easier to find. And there you go. Plug and play it in your own code and let me know how it goes. You can contact me at omondiy@gmail.com and my blog http://datawebke.blogspot.com/.