环顾四周,找不到明确的方法来做到这一点......我需要从在某个 URL 找到的图像中读取元数据。有没有办法在iphone上做到这一点?
问问题
1773 次
2 回答
1
于 2012-06-19T22:49:33.727 回答
1
我尝试使用 iphone-exif,但它在我的项目中不起作用。看到很多人遇到和我一样的错误。
好消息是我找到了另一个解决方案......
NSDictionary *IPTCDict;
NSString *urlString = @"http://SOMEIMAGEURL.jpg";
NSMutableData *photoData = [NSMutableData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)photoData, NULL);
NSDictionary *metadata = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
NSLog(@"Meta: %@", metadata); //Will print out all the metadata
// Pulls out the IPTC data
IPTCDict = [metadata objectForKey:(NSString *)kCGImagePropertyIPTCDictionary];
NSLog(@"Caption: %@\nCopyright: %@", [IPTCDict objectForKey:@"Caption/Abstract"], [IPTCDict objectForKey:@"CopyrightNotice"]);
于 2012-06-20T18:23:27.443 回答