【问题标题】:read xmp metadata from jpeg in ios从ios中的jpeg读取xmp元数据
【发布时间】:2017-07-26 06:10:04
【问题描述】:

我正在尝试从 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 *')

请帮忙

【问题讨论】:

  • CGImageSourceCopyMetadataAtIndex() 返回CGImageMetadataRef。应该如何转换为CFDictionaryRef?这就是你收到警告的原因。也许是CGImageMetadataRef metadaRef = CGImageSourceCopyMetadataAtIndex(source, 0, NULL); NSArray *metadata = CFBridgingRelease(CGImageMetadataCopyTags(metadata)); 而不是字典(来源:stackoverflow.com/questions/25589118/…
  • 谢谢,我改成了 CGImageMetadataRef 但我没有得到所有的元数据,只有我得到了这个: (exif:PixelYDimension = 1024 exif:PixelXDimension = 2048 tiff:Orientation = 1 exif:ColorSpace = 1)
  • 如果要保留所有元数据,则需要将文件数据对象作为数据读取,而不是作为 UIImage。我通过使用这个想法解决了。所以我得到了所有的元数据。

标签: ios objective-c uiimage xmp


【解决方案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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 2011-02-04
    • 2021-05-25
    相关资源
    最近更新 更多