Resolved Having trouble retrieving GPS Coordinates from Image File.

MPIon

Well-known member
Joined
Jun 13, 2020
Messages
81
Location
England
Programming Experience
10+
I am trying to retrieve the GPS Coordinates from a jpg file using c# in a Windows Forms application.

I can retrieve the Latitude Direction for example using :-
C#:
Expand Collapse Copy
ShellFile.FromParsingName(fullPath).Properties.GetProperty(GPS.LatitudeRef).ValueAsObject?.ToString() ?? "";
which typically returns "N".

Can't seem to find the correct syntax to return the Latitude value though using something like :-

C#:
Expand Collapse Copy
double[] xx;
xx = ShellFile.FromParsingName(fullPath).Properties.GetProperty(GPS.Latitude)

Compile error is
Cannot implicitly convert type 'Microsoft.WindowsAPICodePack.Shell.PropertySystem.IShellProperty' to 'double[]'

This despite the documentation saying the Property is a double array.

Have extensively searched the Internet to no avail. No one seems to have a simple example of retrieving this property. (Something I can do easily in VBA using WIA.ImageFile).
 
GetProperty returns the property, you have to get the value from the property with ValueAsObject too, then you get the double array. VS should offer to cast the object to double[] for you.
 
GetProperty returns the property, you have to get the value from the property with ValueAsObject too, then you get the double array. VS should offer to cast the object to double[] for you.
Thanks John, I was thinking of trying the WIA route, but what you suggested has worked. I did try ValueAsObject, but was missing the Cast.

The test code that works is :
C#:
Expand Collapse Copy
double[] xx;
xx = (double[])ShellFile.FromParsingName(fullPath).Properties.GetProperty(GPS.Latitude).ValueAsObject;

In my test code, xx now holds, 51, 46, 24.6359... , which are the correct values for the image.

Thanks again, this has saved me a lot of effort trying to get WIA.ImageFile to work.
 
Back
Top Bottom