Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get image metadata in ios

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.

like image 954
Hardik Shah Avatar asked Sep 18 '12 13:09

Hardik Shah


2 Answers

CGImageSourceRef source = CGImageSourceCreateWithURL( (CFURLRef) aUrl, NULL);
CGImageSourceRef source = CGImageSourceCreateWithData( (CFDataRef) theData, NULL);
NSDictionary* metadata = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source,0,NULL));
CFRelease(source);

Check the dictionary contents here.

like image 179
Jonas Schnelli Avatar answered Oct 03 '22 12:10

Jonas Schnelli


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]
like image 29
Usman Nisar Avatar answered Oct 03 '22 10:10

Usman Nisar