EXIF Location data with camera images

  1. 3 months ago

    Richard A

    May 21 Pre-Release Testers

    I have an iPad app that takes pictures with the camera and have tried both the built in iOSPicturePicker.camera and the add on UIKit.UIImagePickerController.Source.Camera to do so. I store a copy of the image in the device's Photos Library as well as a blob in a SQLite database within the app's document folder.

    It appears that neither way of capturing the picture records the location data in the EXIF metadata for the image. In my database, I can, of course, record the latitude and longitude in separate fields in the same record. However, I would like to be able to send the image copy to Photos Library so that Photos also recognizes the location info. Is this possible?

    Also, a different but related issue, when I use the UIKit image.SaveToCameraRoll extension, my app throws a low memory warning. I'm guessing that the image need to be flushed from memory somehow? This doesn't happen when I use a sharingPanel to send the photo to Photos Library.

    Any thoughts?

  2. Richard A

    May 21 Pre-Release Testers

    @RichardAllmendinger Also, a different but related issue, when I use the UIKit image.SaveToCameraRoll extension, my app throws a low memory warning. I'm guessing that the image need to be flushed from memory somehow? This doesn't happen when I use a sharingPanel to send the photo to Photos Library.

    I think this was just an artifact immediately following an update of the app on the iPad via Xcode devices and simulators. Once I have restarted the iPad, I am able to take photos and copy them automatically to the Library with no memory warnings...

    Still wondering, though, about location EXIF data...

  3. Dave S

    May 21 San Diego, California USA

    @RichardAllmendinger Still wondering, though, about location EXIF data...

    what about it are you wondering. iPhone/iPad cameras store a litney of EXIF data with the picture.

    So is you question more along the lines of how to extract it?

    Doubt there is a simple answer for that question... Seems EXIF is a common additon to digital photos... just a pain to get to

  4. Dave S

    May 21 San Diego, California USA

    Actually using SWIFT or OBJC it is not as difficult as I thought (Xojo is another matter)

    This is SWIFT CODE NOT XOJO... do not CUT/PASTE

    import ImageIO
    
    let fileURL = theURLToTheImageFile
    if let imageSource = CGImageSourceCreateWithURL(fileURL as CFURL, nil) {
        let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)
        if let dict = imageProperties as? [String: Any] {
            print(dict)
        }
    }
  5. Richard A

    May 21 Pre-Release Testers

    @Dave S what about it are you wondering. iPhone/iPad cameras store a litney of EXIF data with the picture.

    So is you question more along the lines of how to extract it?

    Wonder how to send copies of photos taken within my app to the Photos Library with the EXIF data intact. No method of moving those photos to the Library preserve (or perhaps don't even record in the first place) location data with the EXIF info. Use the iosPicturePicker.camera or the UIKit.UIImagePickerController.Source.Camera, send the resulting picture to the Photos Library using either the sharing panel or the image.SaveToCameraRoll extension and Photos Library does not show or recognize any location information for the picture. I am guessing that neither iosPicturePicker.camera or the UIKit.UIImagePickerController.Source.Camera capture location data in the first place...

  6. Jason T

    May 21 Pre-Release Testers, Xojo Pro Sydney, Australia
    Edited 3 months ago

    @RichardAllmendinger are you saving the images as JPEG or PNG? Because PNG does not preserve EXIF data .

  7. Dave S

    May 21 San Diego, California USA

    PNG files "can" (but may not) contain similar MetaData

    https://dev.exiv2.org/projects/exiv2/wiki/The_Metadata_in_PNG_files

  8. Jason K

    May 22 Pre-Release Testers

    @RichardAllmendinger I am guessing that neither iosPicturePicker.camera or the UIKit.UIImagePickerController.Source.Camera capture location data in the first place...

    This is probably correct. You will need to get the UIImage instead of iOSImage if you want that information I would guess. I doubt that iOSImage preserves the data

  9. Richard A

    May 22 Pre-Release Testers

    @Jason T @RichardAllmendinger are you saving the images as JPEG or PNG? Because PNG does not preserve EXIF data

    Thanks for checking, Jason T. I'm saving as JPEG.

    @Jason K This is probably correct. You will need to get the UIImage instead of iOSImage if you want that information I would guess. I doubt that iOSImage preserves the data

    Thanks, Jason K. I'm actually using a snippet of code that, I think, you wrote several years ago to send the image to Photos Library:

    declare sub UIImageWriteToSavedPhotosAlbum lib UIKitLib (img as ptr, target as ptr, sel as ptr, info as ptr)
    UIImageWriteToSavedPhotosAlbum(img.Handle,nil,nil,nil)

    which extends iosImage. Is there a way to grab the UIImage from the UIKit.UIImagePickerController and send it directly to Photos?

    Alternatively, as my app is already location-aware, is there any way to write at least the location EXIF data to the iosImage?

  10. Jason K

    May 22 Pre-Release Testers

    I’m traveling for the next few weeks without my laptop, but you should be able to look at the function that’s returning an iOSImage and instead return the UIImage handle instead of creating the iOSImage. I have no idea if it will work but it’s something to try Incase iOSImage is breaking EXIF data. This is an internals of iOSImage question we may need an engineer to answer.

  11. Jeremie L

    May 22 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io

    I think it is in UIImagePickerController.HandleDidFinishPicking method

    Keeping the ptr reference to original Image and edited Image should help.

  12. Richard A

    May 22 Pre-Release Testers

    Okay, following Jeremie's clue (thanks!) I tried this:

    declare function objectForKey lib FoundationLib selector "objectForKey:" (obj_id as ptr, key as CFStringRef) as ptr
    declare function stringForKey lib FoundationLib selector "objectForKey:" (obj_id as ptr, key as CFStringRef) as CFStringRef
    
    declare sub UIImageWriteToSavedPhotosAlbum lib UIKitLib (img as ptr, target as ptr, sel as ptr, info as ptr)
    UIImageWriteToSavedPhotosAlbum(objectForKey(infoDict,UIImagePickerControllerOriginalImage),nil,nil,nil)

    This successfully writes the image to the Photos Library but also does not include any EXIF info. Looking at this page in Apple docs: https://developer.apple.com/documentation/imageio/cgimageproperties/exif_dictionary_keys I don't actually see any keys for latitude and longitude unless they are buried in the kCGImagePropertyExifSubjectLocation string. I wonder where Apple stores location information in Photos...

or Sign Up to reply!