如何在拍摄的图片的元数据中阅读“{TIFF}”信息

时间:2012-02-21 12:17:01

标签: objective-c xcode nested nsdictionary

我是objective-c的新手,我在UIImagePickerControllerMediaMetaData中读取信息时遇到问题。

-(void) imagePickerController:(UIImagePickerController *)imagepicker didFinishPickingMediaWithInfo:(NSDictionary *)info {

//This line is fine.
NSDictionary *metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];

//This line fail to operate...
NSArray *tiffData = [metadata objectForKey:Exif];

我可以获取元数据。但是,元数据中的信息有点令人困惑,下面显示了内部元数据。

UIImagePickerControllerMediaMetadata =     {
    DPIHeight = 72;
    DPIWidth = 72;
    Orientation = 6;
    "{Exif}" =         {
        ApertureValue = "2.526068811667588";
        BrightnessValue = "-1.739497174308802";
        ColorSpace = 1;
        DateTimeDigitized = "2012:02:21 11:53:44";
        DateTimeOriginal = "2012:02:21 11:53:44";
        ExposureMode = 0;
        ExposureProgram = 2;
        ExposureTime = "0.06666666666666667";
        FNumber = "2.4";
        Flash = 32;
        FocalLenIn35mmFilm = 32;
        FocalLength = "2.03";
        ISOSpeedRatings =             (
            800
        );
        MeteringMode = 5;
        PixelXDimension = 960;
        PixelYDimension = 720;
        SceneType = 1;
        SensingMethod = 2;
        Sharpness = 0;
        ShutterSpeedValue = "3.906905022631062";
        WhiteBalance = 0;
    };
    "{TIFF}" =         {
        DateTime = "2012:02:21 11:53:44";
        Make = Apple;
        Model = "iPad 2";
        Software = "5.0.1";
        XResolution = 72;
        YResolution = 72;
    };
};

那么如何阅读“{Exif}”和“{TIFF}”?

感谢您帮助我。我到处都找到了,但却没有得到答案......

1 个答案:

答案 0 :(得分:8)

{EXIF}{TIFF}条目是元数据字典中包含的字典。您可以使用以下代码获取对它们的引用:

NSDictionary *metadata = [info objectForKey:UIImagePickerControllerMediaMetadata];
NSDictionary *exifMetadata = [metadata objectForKey:(id)kCGImagePropertyExifDictionary];
NSDictionary *tiffMetadata = [metadata objectForKey:(id)kCGImagePropertyTiffDictionary];

CGImageProperties Reference文档页面中描述了所有元数据键。 (id)强制转换是必要的,因为所有密钥都是CFStringRef,并且需要免费桥接到NSString