我正在使用
检索图像func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) }
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
}
我可以检索图像,也可以使用图像输入到按钮背景或我想要的任何其他内容,但我似乎无法检索照片的元数据。现在,在互联网上的其他各个位置有很多关于使用 ALAssets
及其图像数据技术的讨论,但是,ALAssets
最近已被弃用。由于我的图像不是用户刚刚拍摄的图像,而是从相机胶卷中选择的图像,因此我无法使用:
让 metadata = info[UIImagePickerControllerMediaMetaData] as! NSDictionary
因此,如果有人能指出正确的方向,说明如何在不使用 ALAssets 的情况下获取用户刚从相机胶卷中挑选的图像的元数据,我将不胜感激!谢谢!
最佳答案
如果您想从相机胶卷中获取图像,那么这会有所帮助:
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let imageUrl = info["UIImagePickerControllerReferenceURL"]
let asset = PHAsset.fetchAssetsWithALAssetURLs([imageUrl], options: nil).firstObject as! PHAsset
print("location: " + String(asset.location))
print("Creation Date: " + String(asset.creationDate))
}
关于swift - ALAsset 已弃用 - 使用 Photos Framework 中的 PHAsset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36492423/