Retrieving EXIF (GPS) data from UIImage

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieving EXIF (GPS) data from UIImage

ric3kg
I'm trying to retrieve GPS data from photo imported from a Photo Album. Apple has a tech note on how to do this (http://developer.apple.com/library/ios/ipad/#qa/qa1654/_index.html). But I can't find CGImageSourceRef in Monotouch. Am I missing something? I'm using Monotouch 5.2.13.

I can get the data from AssetLibrary calls but how does one get there from an UIImage object?

Thanks,
Rick
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving EXIF (GPS) data from UIImage

Craig Dunn-2
Just to clarify, you can't get this info from a UIImage object, because that object is just for loading/displaying images.

You *can* get the info direct from an image *file* (with an NSUrl reference) using the ImageIO framework (as per that example you linked to). Here's the MonoTouch equiv...

// Ensure you have these 'using'

using MonoTouch.Foundation;

using MonoTouch.UIKit;

using MonoTouch.CoreFoundation;

using MonoTouch.ImageIO;


// Then put this in your code somewhere

var url = new NSUrl("myPhoto.JPG", false);  // could be an NSUrl to asset lib...

CGImageSource myImageSource;

myImageSource = CGImageSource.FromUrl (url, null);

var ns = new NSDictionary();

var imageProperties = myImageSource.CopyProperties(ns, 0);

var width = imageProperties[CGImageProperties.PixelWidth];

var height = imageProperties[CGImageProperties.PixelHeight];

Console.WriteLine("Dimensions: {0}x{1}", width, height); 

// Output all teh things

Console.WriteLine(imageProperties.DescriptionInStringsFileFormat)


HTH
craig






On Thu, Aug 16, 2012 at 10:55 PM, ric3kg <[hidden email]> wrote:
I'm trying to retrieve GPS data from photo imported from a Photo Album. Apple
has a tech note on how to do this
(http://developer.apple.com/library/ios/ipad/#qa/qa1654/_index.html). But I
can't find CGImageSourceRef in Monotouch. Am I missing something? I'm using
Monotouch 5.2.13.

I can get the data from AssetLibrary calls but how does one get there from
an UIImage object?

Thanks,
Rick



--
View this message in context: http://monotouch.2284126.n4.nabble.com/Retrieving-EXIF-GPS-data-from-UIImage-tp4656547.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving EXIF (GPS) data from UIImage

ric3kg
I don't see any GPS info in your example. Here's what I'm trying:

public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
                {
                        var mediaUrlKey = new NSString("UIImagePickerControllerReferenceURL");
    var mediaPath = (NSUrl) editingInfo.ObjectForKey(mediaUrlKey);
    ALAssetsLibrary al = new ALAssetsLibrary();
                                al.AssetForUrl(keyInfo, (asset) => {
                                        if(asset.Location != null)
                                        {
                                                lat = asset.Location.Coordinate.Latitude.ToString();
                                                lon = asset.Location.Coordinate.Longitude.ToString();
                                        }
                                }, (error) => {
                                        Log.WriteLog("Error in GetGPS");
                                });
        }

I get the Asset URL but no GPS data. I know it's there because when I get the image using the AssetLibrary block to get the entire album, the same Location extraction code works.

Thanks,
Rick
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving EXIF (GPS) data from UIImage

Craig Dunn-2
Well, the example was a line-for-line port of the Objective-C link you asked about. Examining this property that I included in the example

// Output all teh things
Console.WriteLine(imageProperties.DescriptionInStringsFileFormat)

shows that the following information can be accessed

"{GPS}" = {
    Altitude = 5;
    AltitudeRef = 0;
    ImgDirection = "178.7823";
    ImgDirectionRef = T;
    Latitude = "33.8945";
    LatitudeRef = S;
    Longitude = "151.2275";
    LongitudeRef = E;
    TimeStamp = "10:17:19.90";
};

and this sample code (added to the previous code that creates imageProperties) extracts it

var gps = imageProperties.ObjectForKey(new NSString("{GPS}")) as NSDictionary;
var lat = gps.ObjectForKey(new NSString("Latitude"));
var latref = gps.ObjectForKey(new NSString("LatitudeRef"));
var lon = gps.ObjectForKey(new NSString("Longitude"));
var lonref = gps.ObjectForKey(new NSString("LongitudeRef"));
Console.WriteLine("Location: {0}{1}x{2}{3}", lat, latref, lon, lonref);

it outputs : Location: 33.8945Sx151.2275E



On Fri, Aug 17, 2012 at 11:33 PM, ric3kg <[hidden email]> wrote:
I don't see any GPS info in your example. Here's what I'm trying:

public override void FinishedPickingImage (UIImagePickerController picker,
UIImage image, NSDictionary editingInfo)
                {
                        var mediaUrlKey = new NSString("UIImagePickerControllerReferenceURL");
                        var mediaPath = (NSUrl) editingInfo.ObjectForKey(mediaUrlKey);
                        ALAssetsLibrary al = new ALAssetsLibrary();
                                al.AssetForUrl(keyInfo, (asset) => {
                                        if(asset.Location != null)
                                        {
                                                lat = asset.Location.Coordinate.Latitude.ToString();
                                                lon = asset.Location.Coordinate.Longitude.ToString();
                                        }
                                }, (error) => {
                                        Log.WriteLog("Error in GetGPS");
                                });
        }

I get the Asset URL but no GPS data. I know it's there because when I get
the image using the AssetLibrary block to get the entire album, the same
Location extraction code works.

Thanks,
Rick



--
View this message in context: http://monotouch.2284126.n4.nabble.com/Retrieving-EXIF-GPS-data-from-UIImage-tp4656547p4656559.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving EXIF (GPS) data from UIImage

fSurprenant
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Not sure if you ever figured a way to get the GPS data from an image in the photo gallery or not, But i've been working on that same thing of a week now. Any input would be greatly appreciated. Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving EXIF (GPS) data from UIImage

ric3kg
I could only get it if I went through the ALAssetsLibrary method. Once you get the asset you want you can use: asset.Location.Coordinate.Latitude and asset.Location.Coordinate.Longitude.

After picking an image I call the following method and pass in the NSDictionary. The iconID is just my stuff.
public static void GetGPS(NSDictionary editingInfo, string iconID) //(UIImage image)
                {
                        try
                        {
                                var mediaUrlKey = new NSString("UIImagePickerControllerReferenceURL"); //UIImagePickerControllerMediaURL
    var keyInfo = (NSUrl) editingInfo.ObjectForKey(mediaUrlKey);

                                //http://developer.apple.com/library/ios/ipad/#qa/qa1654/_index.html
                                ALAssetsLibrary al = new ALAssetsLibrary();
                                al.AssetForUrl(keyInfo, (asset) => {
                                        if(asset.Location != null)
                                        {
                                                var nIcon = appDelegate.store.db.IconReadSafe(iconID);
                                                nIcon.latitude = asset.Location.Coordinate.Latitude.ToString();
                                                nIcon.longitude = asset.Location.Coordinate.Longitude.ToString();
                                                appDelegate.store.db.IconSave(nIcon);
                                        }
                                }, (error) => {
                                        Log.WriteLog("Error in GetGPS "+error.LocalizedDescription);
                                });

                        }
                        catch(Exception ex)
                        {
                                Log.LogError("GetLongitude",ex);
                        }
                }