I can not understand why metaDic is always null. There is a code.
CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(img.CGImage)); //(UIImage *img)
CGImageSourceRef mySourceRef = CGImageSourceCreateWithData(dataRef, NULL);
NSDictionary *metaDic = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(mySourceRef,0,NULL);
NSDictionary *tiffDic = (NSDictionary *)[metaDic objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
NSString *AuthorName = [tiffDic objectForKey:(NSString *)kCGImagePropertyTIFFArtist];
I did some variants of getting picture. And here what I have discovered:
One way of getting picture with its info - I need to get it from site and there what I've got:
// NSURL *UrlPath - path of picture image.jpg from web site
NSData *dataImg = [NSData dataWithContentsOfURL:UrlPath];
CGImageSourceRef mySource = CGImageSourceCreateWithData((CFDataRef)dataImg, NULL);
NSDictionary *metaDic = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(mySource,0,NULL);
NSDictionary *tiffDic = [metaDic objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
/// Log of tiffDic
tiffDic = {
Artist =(
"mr. Smith"
);
}
another way - read picture from NSBoudle mainBundle:
// NSURL *NSBundleUrl - - path of the same picture image.jpg from [[NSBundle mainBundle]
CGImageSourceRef mySource = CGImageSourceCreateWithURL( (CFURLRef) NSBundleUrl, NULL);
NSDictionary *metaDic = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(mySource,0,NULL);
NSDictionary *tiffDic = [metaDic objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
/// Log of tiffDic
tiffDic = {
Artist = "mr. Smith";
}
why it get braces as array for name of artist when the picture data come from web site?