ios - 使用 EXIF/geotag 信息更新内存中的 iOS UIImage

标签 ios image uiimage exif

我正在尝试使用地理标记信息更新 UIImage。我看了Saving Geotag info with photo on iOS4.1 ,这是我找到对 NSMutableDDictionary+ImageMetadata category 的引用的地方.不过,我不想保存到相册,而是有一个UIImage传过去

以下代码似乎制作了太多图像副本,并且需要链接所有这些框架:CoreImage、AssetsLibrary、CoreMedia、ImageIO。

有没有比 UIImage -> CIImage -> CGImage -> UIImage 更高效的东西设置 EXIF 数据所需的属性 NSDictionary?

- (UIImage *)updateImage:(UIImage *)image location:(CLLocation *)location dateOriginal:(NSDate *)dateOriginal
{
    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary:[image.CIImage properties]];

    // uses https://github.com/gpambrozio/GusUtils   
    [properties setLocation:location];
    [properties setDateOriginal:dateOriginal];

    CIImage *tempImage = [[CIImage alloc] initWithImage:image options:properties];
    CIContext *context = [CIContext contextWithOptions:nil];    
    UIImage *updatedImage = [UIImage imageWithCGImage:[context createCGImage:tempImage fromRect:tempImage.extent]];

    return updatedImage;
}

最佳答案

看看 libexif:http://libexif.sourceforge.net/

您可能需要使用以下方法将图像的字节数据传递给库

UIImageJPEGRepresentation(image, quality) bytes]

关于ios - 使用 EXIF/geotag 信息更新内存中的 iOS UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9051326/

相关文章:

iPhone - 比较日期不按预期工作

image - 如何修复不完整的网格单元并修复图像中缺失的部分

ios - 请帮我找出这个 Objective-C 方法 (iOS) 中的内存泄漏

objective-c - 从 web 服务器为视网膜显示 iOS 下载图像

ios - UIImage 显示在模拟器上,而不是在真实设备上

ios - 在 iPad 上更改方向后 Fancybox 无法正确重新定位

ios - 将值(value)传递给私有(private)属性(property)

ios - Apple 说即使 wifi 已连接也无法连接到 wifi

html - 填充是链接的一部分

Flutter 中具有透明背景的图像