public func setExiffrom(url:URL?){
if url == nil{
return
}
let imagedata = try! Data.init(contentsOf: url!)
let source: CGImageSource = CGImageSourceCreateWithData((imagedata as CFData), nil)!
if let object = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [String: Any]{
self.imageView.image = UIImage(data: imagedata)
self.exif = Exif(object)
self.textView.text = self.exif?.gps?.getFormattedString(valueSeperator: " = ", lineSeperator: "")
}
}
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
let url = info[UIImagePickerControllerImageURL] as? URL
self.imageView.image = image
self.choosenImage = image
self.setExiffrom(url: url)
self.dismiss(animated: true, completion: nil)
}
我想将读取用户照片的位置并入应用程序,因此我了解了exif以及如何存储经纬度。我曾帮助我进行编码,对于应用程序中的某些图像,它将解析出所选图像中的exif很好...但是,对于大多数图像,exif中没有位置数据。我在iOS照片应用中检查了一下,并在其中正确显示了所有图像的位置数据(在照片上弹出将其显示在地图上)
我也在Macbook上进行了测试,发现了一些令人惊讶的东西。当我右键单击并单击Macbook上“照片”应用程序上的图像上的“获取信息”时,它会显示位置,但将其复制到桌面后,它便不再具有位置数据。也许是一项新的安全功能?
我的问题是我该如何编写一个能够正确获取位置的应用程序,以便该应用程序可以帮助用户捕获记忆?如果手机的“照片”应用可以看到该位置,则意味着数据在那里,因此令人沮丧的是,每当复制图像时,都会出现位置数据被剥离的情况。也许我需要以某种方式读取数据,然后再调用“ let image = info [UIImagePickerControllerOriginalImage]”,因为这会以某种方式剥离位置信息?
-任何帮助,将不胜感激,我很沮丧...
答案 0 :(得分:1)
我正在为我的应用程序使用PHAsset(),看看它。您不必检查exif数据即可获取图像的位置。我认为您也可以对UIImagePicker使用相同的属性(location.coordinate)..但我不确定
// request options for PHAsset
let allPhotosOptions = PHFetchOptions()
allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
// get the requested AssetData
fetchResult = PHAsset.fetchAssets(with: allPhotosOptions)
// check if we got any
if fetchResult != nil {
// loop over result
for index in 0 ..< fetchResult!.count {
// take the next item
let item = fetchResult!.object(at: index)
// check if it is a photo
if item.mediaType == .image {
// yes, it is a photo, so check location
// check if the location data is valid
if item.location != nil {
// as an example: create a mapPoint from the coordination
let locationPoint = MKMapPointForCoordinate(item.location!.coordinate)
} // location not nil
} // is an image
} // loop
} // result not nil
答案 1 :(得分:0)
以防万一,我在Apple开发人员的论坛上发现了该线程... https://forums.developer.apple.com/thread/96160