iOS - 从UIImage检索EXIF UserComment

psa*_*gio 0 jpeg exif ios

我在JPEG图像的EXIF标题的UserComment字段中有一些重要的元数据信息.我试图用它来检索它

NSData* jpgData = UIImageJPEGRepresentation(uiImage, 1.0);

CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)jpgData, NULL);
NSDictionary *metadata = (__bridge NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);

NSDictionary *img_metadata = [metadata objectForKey:(NSString*)kCGImagePropertyExifDictionary];

NSString* user_comment = [img_metadata objectForKey:(NSString*)kCGImagePropertyExifUserComment];
Run Code Online (Sandbox Code Playgroud)

但是,我得到的img_metadata词典不再包含用户注释,即使它仍然有其他字段,如颜色空间和图像尺寸?有没有办法从UIImage对象获取用户注释?

ale*_*x-i 8

UIImage表示解码图像,并丢弃元数据.重新编码的数据(在您的情况下为UIImageJPEGRepresentation)仍将包含颜色空间,图像大小和方向等信息,因为在编码/解码操作期间可能需要这些信息.

获取元数据的唯一方法是使用原始图像数据,无法从中获取UIImage.