How to get image metadata in ios

后端 未结 9 1749
独厮守ぢ
独厮守ぢ 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:47

    Reading image properties via Core Graphics wrapped as Swift struct:

    struct ImageMetadata {
    
        var imageProperties : [CFString: Any]
    
        init?(data: Data) {
            let options = [kCGImageSourceShouldCache: kCFBooleanFalse]
            if let imageSource = CGImageSourceCreateWithData(data as CFData, options as CFDictionary),
                let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [CFString: Any] {
                self.imageProperties = imageProperties
            } else {
                return nil
            }
        }
    
        var dpi : Int? { imageProperties[kCGImagePropertyDPIWidth] as? Int }
        var width : Int? { imageProperties[kCGImagePropertyPixelWidth] as? Int }
        var height : Int? { imageProperties[kCGImagePropertyPixelHeight] as? Int }
    
    }
    

提交回复
热议问题