なんかだか面倒くさいけど、これライブラリないんだろうか。
static NSDictionary *getExifFromData(NSData * const data)
{
CFStringRef imageSourceOptionKeys[2];
CFTypeRef imageSourceOptionValues[2];
imageSourceOptionKeys[0] = kCGImageSourceShouldCache;
imageSourceOptionValues[0] = kCFBooleanTrue;
imageSourceOptionKeys[1] = kCGImageSourceShouldAllowFloat;
imageSourceOptionValues[1] = kCFBooleanTrue;
CFDictionaryRef imageSourceOptions = CFDictionaryCreate(
NULL,
(const void **)imageSourceOptionKeys,
(const void**)imageSourceOptionValues,
sizeof(imageSourceOptionKeys) / sizeof(imageSourceOptionKeys[0]),
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CGImageSourceRef imageSourceRef = CGImageSourceCreateWithData((__bridge CFDataRef) data, imageSourceOptions);
CFRelease(imageSourceOptions);
CFDictionaryRef imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(imageSourceRef, 0, NULL);
NSDictionary *exif = (__bridge NSDictionary *)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyExifDictionary);
CFRelease(imageSourceRef);
return exif;
}
うまくいくと以下の様なメタデータがとれる。
// NSLog("exif: %@, exif);
exif: {
ColorSpace = 1;
ComponentsConfiguration = (
1,
2,
3,
0
);
DateTimeDigitized = "2012:10:15 20:57:48";
DateTimeOriginal = "2012:10:15 20:57:48";
ExifVersion = (
2,
2,
1
);
FlashPixVersion = (
1,
0
);
PixelXDimension = 1536;
PixelYDimension = 1536;
SceneCaptureType = 0;
}
参考文献: