5

我正在使用检索图像

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) }
      let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
}

我可以检索图像,也可以使用图像输入按钮背景或我想要的任何其他内容,但我似乎无法检索照片的元数据。现在,有很多关于使用互联网上其他各种位置的讨论,ALAssets以及它们用于图像数据的技术,但ALAssets最近已被弃用。由于我的图像不是用户刚刚拍摄的图像,而是从相机胶卷中选择的图像,因此我无法使用:

let metadata = info[UIImagePickerControllerMediaMetaData] as! NSDictionary

因此,如果有人能指出正确的方向,即如何在不使用 ALAssets 的情况下获取用户刚刚从相机胶卷中挑选的图像的元数据,我们将不胜感激!谢谢!

4

2 回答 2

6

如果您想从相机胶卷中获取图像,那么这将有所帮助:

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))

}
于 2016-04-08T05:56:11.560 回答
-1

来自Muhammad Yawar Ali的 Objective-C 解决方案回答:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    NSString * imageUrl = info[@"UIImagePickerControllerReferenceURL"];
    PHAsset * asset = [[PHAsset fetchAssetsWithALAssetURLs:[NSArray arrayWithObject:imageUrl] options:nil]firstObject];
    NSLog(@"location: %@",asset.location);
    NSLog(@"Creation Date: %@",asset.creationDate);
}
于 2018-03-14T08:58:25.073 回答