我想在Swift中使用UIImagePickerController显示图像元数据。 从图库中选择图像,并在图像视图中显示元素数据,如PixelHeight,PixelWidth,PixelXDimension,PixelYDimension,坐标,大小,创建日期和图像名称。
答案 0 :(得分:5)
首先,您可以从UIImagePickerController获取信息[UIImagePickerControllerReferenceURL]。然后你可以做以下事情:
let assetURL = info[UIImagePickerControllerReferenceURL] as! NSURL
let asset = PHAsset.fetchAssetsWithALAssetURLs([assetURL], options: nil)
guard let result = asset.firstObject where result is PHAsset else {
return
}
let imageManager = PHImageManager.defaultManager()
imageManager.requestImageDataForAsset(result as! PHAsset, options: nil, resultHandler:{
(data, responseString, imageOriet, info) -> Void in
let imageData: NSData = data!
if let imageSource = CGImageSourceCreateWithData(imageData, nil) {
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
//now you have got meta data in imageProperties, you can display PixelHeight, PixelWidth, etc.
}
})