2

i'm trying to get xmp metadata information from a 360° jpeg file. So, i wrote this code but i didn't get the xmp information:

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

i had also a warning : Incompatible pointer types initializing 'CFDictionaryRef' (aka 'const struct __CFDictionary *') with an expression of type 'CGImageMetadataRef _Nullable' (aka 'const struct CGImageMetadata *')

Any help please

Walid Sassi
  • 185
  • 2
  • 16
  • `CGImageSourceCopyMetadataAtIndex()` returns a `CGImageMetadataRef`. How is is supposed to be transformed into a `CFDictionaryRef`? That's why you get a warning. Maybe with `CGImageMetadataRef metadaRef = CGImageSourceCopyMetadataAtIndex(source, 0, NULL); NSArray *metadata = CFBridgingRelease(CGImageMetadataCopyTags(metadata));` and not a Dictionary (source: http://stackoverflow.com/questions/25589118/stripping-all-exif-data-in-objective-c) – Larme Mar 06 '17 at 12:31
  • thank you, i changed to CGImageMetadataRef but i didn't get all the meta data only i got this : ( exif:PixelYDimension = 1024 exif:PixelXDimension = 2048 tiff:Orientation = 1 exif:ColorSpace = 1 ) – Walid Sassi Mar 06 '17 at 12:41
  • If you want to retain all of the metadata, you need to read the file data object as data, not as UIImage. i resolved by using this idea. so i get all the metadata. – Walid Sassi Mar 06 '17 at 13:44

1 Answers1

0

i solved by passing all the data not the 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);
}
Walid Sassi
  • 185
  • 2
  • 16