【问题标题】:How to get Exif data from local image using Swift?如何使用 Swift 从本地图像中获取 Exif 数据?
【发布时间】:2018-02-13 03:04:22
【问题描述】:

如果我们在 Assets.xcassets 中有图像 imageName.jpg,让我们像这样将该图像放入 UIImage 中:

let imageForExif: UIImage = UIImage(named: "imageName.jpg")! 

我们如何使用 Swift 从 imageForExif 获取(提取)Exif 数据?

【问题讨论】:

    标签: ios swift uiimage exif


    【解决方案1】:

    试试这个...

      if let imageData = UIImageJPEGRepresentation(imageForExif, 1.0) {
            let imageCFData = imageData as CFData
            if let cgImage = CGImageSourceCreateWithData(imageCFData, nil), let metaDict: NSDictionary = CGImageSourceCopyPropertiesAtIndex(cgImage, 0, nil) {
                let exifDict: NSDictionary = metaDict.object(forKey: kCGImagePropertyExifDictionary) as! NSDictionary
                print(exifDict)
            }
        }
    

    但您的可用数据可能非常有限。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      相关资源
      最近更新 更多