我不明白为什么 metaDic 总是为空。有一个代码。
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];
我做了一些获取图片的变体。在这里我发现了什么:
使用其信息获取图片的一种方法-我需要从站点获取它,并且那里有我所拥有的:
// 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"
);
}
另一种方式 - 从 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";
}
当图片数据来自网站时,为什么它将大括号作为艺术家姓名的数组?