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.
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…
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)
}
}
[quote=437576:@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?
[/quote]
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…
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?
Im traveling for the next few weeks without my laptop, but you should be able to look at the function thats returning an iOSImage and instead return the UIImage handle instead of creating the iOSImage. I have no idea if it will work but its something to try Incase iOSImage is breaking EXIF data. This is an internals of iOSImage question we may need an engineer to answer.
Okay, following Jeremie’s clue (thanks!) I tried this:
[code]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)[/code]
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…