μ-Blog

μFactory管理人が、誰かに役に立つかもしれない情報をまとめたブログです

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];

参考

この後、回転させる方法は以下を参考に...