How to get image metadata in ios

后端 未结 9 1744
独厮守ぢ
独厮守ぢ 2020-11-29 06:18

I want to display image metadata using ios. Meta data like Aperture, Shutterspeed, Exposure Compensation, ISO, Lens Focal Length, etc. So please help me if anybody has idea

9条回答
  •  孤城傲影
    2020-11-29 06:51

    Answering my own question. The memory-effective and fast way to get a GPS metadata is

    let options = [kCGImageSourceShouldCache as String: kCFBooleanFalse]
    if let data = NSData(contentsOfURL: url), imgSrc = CGImageSourceCreateWithData(data, options) {
        let metadata = CGImageSourceCopyPropertiesAtIndex(imgSrc, 0, options) as Dictionary
        let gpsData = metadata[kCGImagePropertyGPSDictionary] as? [String : AnyObject]
    }
    

    The second option is

    if let img = CIImage(contentsOfURL: url), metadata = img.properties(), 
    gpsData = metadata[kCGImagePropertyGPSDictionary] as? [String : AnyObject] { … }
    

    it looks nicer in Swift but uses more memory (tested via Profiler).

提交回复
热议问题