How to get image metadata in ios

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

    Here is code, to get meta data from an image path:

    NSData *imagedata = [NSData dataWithContentsOfFile:imagePath];
    CGImageSourceRef source = CGImageSourceCreateWithData((CFMutableDataRef)imagedata, NULL);
    NSDictionary *metadata = [(NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL)autorelease];
    

    Or, if using swift 4.0:

    var imagedata = Data(contentsOfFile: imagePath) 
    var source: CGImageSourceRef = CGImageSourceCreateWithData((imagedata as? CFMutableDataRef), nil) 
    var metadata = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [AnyHashable: Any]
    

提交回复
热议问题