【问题标题】:Custom defined file metadata keys [Swift]自定义文件元数据键 [Swift]
【发布时间】:2019-12-21 12:16:25
【问题描述】:

我目前正在尝试使用其他自定义元数据(例如热温度统计等)保存 UIImage 的 jpeg 表示。这些不适合苹果预定义的键 (https://developer.apple.com/documentation/imageio/cgimageproperties),因此我找到的解决方案不适用于我的场景。

我尝试将元数据与图像一起保存为键和值的字典,但图像在保存时没有附加元数据。

func saveImage(imageToSave: UIImage, metadata: NSMutableDictionary) {
    if let data: Data = imageToSave.jpegData(compressionQuality: ThermalImageView.JPEG_COMPRESSION) {
        let fileName = self.buildFileName();
        let source = CGImageSourceCreateWithData(data as CFData, nil)!;
        let uniformTypeIdentifier = CGImageSourceGetType(source)!;
        let destination = CGImageDestinationCreateWithURL(fileName as CFURL, uniformTypeIdentifier, 1, nil)!;
        CGImageDestinationAddImageFromSource(destination, source, 0, metadata);
        CGImageDestinationFinalize(destination);
    }
}

当我尝试使用 ExifTool (exiftool -j filename.jpg) 读取这些值时,找不到元数据。我预计会发生这种情况,因为 Apple 似乎限制了您可以添加到元数据中的密钥。那么,有没有办法做到这一点,还是我应该走另一条路?

谢谢!

编辑:我想我可能在这里叫错了树。看来我真正想做的是用额外的元数据修改标题。

【问题讨论】:

    标签: ios swift exif


    【解决方案1】:

    Photos 框架是处理资产元数据的一种方式。此外,PHAsset 是您想要修改的对象。 https://developer.apple.com/documentation/photokit/phasset 一个相关的问题是:https://forums.developer.apple.com/thread/60664

    如果您仍想以目前的方式拥有它,不妨试试这个? https://github.com/Nikita2k/SimpleExif

    【讨论】:

    • 感谢您的回答!但是,我不希望在照片库中存储与图像关联的预定义元数据。我希望将图像上传到服务器,以后可以使用 ExifTool 从图像本身中提取元数据。在您链接的库中,您可以看到他们正在使用“允许的”exif 键(例如github.com/Nikita2k/SimpleExif/blob/master/Classes/…)。我正在寻找定义自己的密钥。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    • 2020-12-14
    • 1970-01-01
    相关资源
    最近更新 更多