首页 > 解决方案 > 从 NSImage 读取 EXIF 数据

问题描述

我有一个快速的 macOS 应用程序,我一直在使用它从磁盘上的照片中读取 EXIF 元数据。使用以下代码段效果很好

let photoURL = NSURL(fileURLWithPath: imageFilename.path)
    if let imageSource = CGImageSourceCreateWithURL(photoURL,nil) {
        if let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary? {// Grab all of the properties ! replaced with ?
            if let exifDict = imageProperties[kCGImagePropertyExifDictionary]

我现在希望能够从存储在我的应用程序资产中的 NSImage 中读取 EXIF 数据

我有可以访问图像的代码

let myphoto = NSImage(named:NSImage.Name(rawValue: "myPhoto"))

我只是不知道如何在 NSImage 和获取 CGImageSource 之间架起桥梁,所以我可以访问 EXIF 字典

标签: swiftimagemacoscore-graphics

解决方案


推荐阅读