从ios中的jpeg中读取xmp元数据

时间:2017-03-06 11:30:57

标签: ios objective-c uiimage xmp

我正在尝试从360°jpeg文件中获取xmp元数据信息。所以,我写了这段代码,但我没有得到xmp信息:

UIImage *img = [UIImage imageNamed:@"park_2048.jpg"];
    NSData *imagedata = UIImageJPEGRepresentation(img, 1);
    CGImageSourceRef source = CGImageSourceCreateWithData( (CFDataRef) imagedata, NULL);
    CFDictionaryRef dictRef = CGImageSourceCopyMetadataAtIndex(source, 0, NULL);
    NSDictionary* metadata = (__bridge NSDictionary *)dictRef;
    NSLog(@"metadata = %@", metadata); 

我还有一个警告:Incompatible pointer types initializing 'CFDictionaryRef' (aka 'const struct __CFDictionary *') with an expression of type 'CGImageMetadataRef _Nullable' (aka 'const struct CGImageMetadata *')

请帮助

1 个答案:

答案 0 :(得分:-1)

我通过传递所有数据而不是UIImage来解决:

NSString* path = [[NSBundle mainBundle] pathForResource:@"park_2048" ofType:@"jpg"];
 NSData *data = [NSData dataWithContentsOfFile:path];
 [self logMetaDataFromImage:data];

- (void) logMetaDataFromImage:(NSData*)imageData {
    NSLog(@"%@",NSStringFromSelector(_cmd));
    CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
    CGImageMetadataRef imageMetaData = CGImageSourceCopyMetadataAtIndex(source,0,NULL);
    NSLog (@"meta data = %@",imageMetaData);
}