Cocoa環境でEXIFの回転情報を得る方法
自分用メモもかねて...多分こんな感じです。
NSData *imageData = [[NSData alloc] initWithContentsOfFile:filePath];
CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
CFNumberRef orientationRef = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
SInt32 orientation;
if(!orientationRef){
// orientationがない場合
} else {
CFNumberGetValue(orientationRef, kCFNumberIntType, &orientation);
CFRelease(orientationRef);
}
CFRelease(imageSource);
CFRelease(properties);
[imageData release];
参考
- CGImageProperties Reference :
http://developer.apple.com/documentation/GraphicsImaging/Reference/CGImageProperties_Reference/Reference/reference.html#//apple_ref/doc/uid/TP40005103-CH3g-DontLinkElementID_4 - Cocoa EXIF rotation :
http://jwz.livejournal.com/986672.html
この後、回転させる方法は以下を参考に...