I am developing a system that allows for an image to be uploaded to a server using ASP.NET C#. I am processing the image and all is working great. I have managed to find a method that reads the Date Created EXIF data and am parsing it as a DateTime. That works great too.
I am now trying to read GPS data from the EXIF. I am wanting to capture the Latitude and Longitude figures.
I am using this list as a reference to the EXIF data (using the numbers for the property items) http://www.exiv2.org/tags.html
Here is the method to capture the date created (which works).
public DateTime GetDateTaken(Image targetImg)
{
DateTime dtaken;
try
{
//Property Item 306 corresponds to the Date Taken
PropertyItem propItem = targetImg.GetPropertyItem(0x0132);
//Convert date taken metadata to a DateTime object
string sdate = Encoding.UTF8.GetString(propItem.Value).Trim();
string secondhalf = sdate.Substring(sdate.IndexOf(" "), (sdate.Length - sdate.IndexOf(" ")));
string firsthalf = sdate.Substring(0, 10);
firsthalf = firsthalf.Replace(":", "-");
sdate = firsthalf + secondhalf;
dtaken = DateTime.Parse(sdate);
}
catch
{
dtaken = DateTime.Parse("1956-01-01 00:00:00.000");
}
return dtaken;
}
Below is my attempt at doing the same for GPS..
public float GetLatitude(Image targetImg)
{
float dtaken;
try
{
//Property Item 0x0002 corresponds to the Date Taken
PropertyItem propItem = targetImg.GetPropertyItem(2);
//Convert date taken metadata to a DateTime object
string sdate = Encoding.UTF8.GetString(propItem.Value).Trim();
dtaken = float.Parse(sdate);
}
catch
{
dtaken = 0;
}
return dtaken;
}
The value that's coming out and into sdate is "5\0\0\0\0\0\0l\t\0\0d\0\0\0\0\0\0\0\0\0\0"
And that is coming from an image that was taken by an iPhone 4 which does carry the GPS EXIF data.
I know there are classes out there that do this but would prefer to write my own - I am open to suggestions though :-)
Thanks in advance.