I am getting hung up on reading EXIF data from my JPEGs. I thought it would be easy to do.
Thus far I have completed the following steps for my family's online image gallery (using C#/ASP.Net 3.5):
I would like to extract the latitude and longitude from the original JPEG image and then insert those values into my database in the same proc that inserts the filename and category ID (step # 5). I need these values to work with the Google Maps API. What is the simplest way to do it?
Update:
ExifLib looks great, but when I do the following:
double d;
ExifReader er = new ExifReader(sFileName);
er.GetTagValue<double>(ExifTags.GPSLatitude, out d);
I get this error on the last line:
Specified cast is not valid.
Any suggestions?
Viewing EXIF data in Windows is easy. Just right-click on the photo in question and select “Properties”. Click on the “Details” tab and scroll down—you'll see all kinds of information about the camera used, and the settings the photo was taken with.
The exchangeable image file format (EXIF) is a standard for embedding technical metadata in image files that many camera manufacturers use and many image-processing programs support. EXIF metadata can be embedded in TIFF and JPEG images.
To bring all the answers together, here is the completed solution.
using (ExifReader reader = new ExifReader(e.Target))
{
Double[] GpsLongArray;
Double[] GpsLatArray;
Double GpsLongDouble;
Double GpsLatDouble;
if (reader.GetTagValue<Double[]>(ExifTags.GPSLongitude, out GpsLongArray)
&& reader.GetTagValue<Double[]>(ExifTags.GPSLatitude, out GpsLatArray))
{
GpsLongDouble = GpsLongArray[0] + GpsLongArray[1] / 60 + GpsLongArray[2] / 3600;
GpsLatDouble = GpsLatArray[0] + GpsLatArray[1] / 60 + GpsLatArray[2] / 3600;
Console.WriteLine("The picture was taken at {0},{1}", GpsLongDouble, GpsLatDouble);
}
}
Output:
The picture was taken at 76.8593333333333,39.077
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With