如何使用Swift从本地映像获取Exif数据?

时间:2022-01-09 16:22:54

If we have image imageName.jpg in Assets.xcassets and let's put that image in UIImage like this:

如果我们在Assets.xcassets中有图像imageName.jpg,那么让我们把这个图像放在UIImage中:

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

How we can get (extract) Exif data from imageForExif using Swift?

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

1 个解决方案

#1


1  

Try this...

  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)
        }
    }

But you may have very limited data available. Hope it helps.

但是,您可能拥有非常有限的数据。希望能帮助到你。

#1


1  

Try this...

  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)
        }
    }

But you may have very limited data available. Hope it helps.

但是,您可能拥有非常有限的数据。希望能帮助到你。