Search code examples
swiftfilecocoansimage

How to get the Color Profile data for an image on disk in swift


Can't quite get how to programmatically get everything in the More Info section for any given photo in swift. I specifically am interested in Color profile data. Any ideas?

Ordinary file information


Solution

  • Turned out to be quite easy:

    let path = // Some Image path on disk
    let url = NSURL.fileURL(withPath: path)
    let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil)
    if imageSource != nil {
    let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource!, 0, nil)
    var dict = imageProperties as! Dictionary<String, Any>
    print(dict["ProfileName"]!)
    }