4

I want to display image metadata using UIImagePickerController in Swift. where the image is been selected from gallery and would be displayed in the imageView along with the meta data such as PixelHeight,PixelWidth,PixelXDimension,PixelYDimension,Coordinates,Size,Date Created and Imagename.

vishal aanuj
  • 53
  • 2
  • 5
  • 2
    Possible duplicate of [Getting metadata in swift by UIImagepickerController](http://stackoverflow.com/questions/26391158/getting-metadata-in-swift-by-uiimagepickercontroller) – Scriptable Jul 03 '16 at 11:26

1 Answers1

6

At first, you can get info[UIImagePickerControllerReferenceURL] from UIImagePickerController. Then you can do things like the following:

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.
        }
    })
SuperBi
  • 278
  • 1
  • 2
  • 9