首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS Swift无法在存储的照片上访问EXIF数据

iOS Swift无法在存储的照片上访问EXIF数据
EN

Stack Overflow用户
提问于 2017-09-26 13:08:00
回答 1查看 108关注 0票数 0

我需要在设备照片库中找到照片的位置。为此,我试图加载图像的Exif数据。这是我的密码:

代码语言:javascript
复制
   import ImageIO

   func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
       let image = info[UIImagePickerControllerOriginalImage] as? UIImage
       let ciImage = CIImage(image: image!)
       let imageProperties = CGImageSourceCopyPropertiesAtIndex(ciImage as! CGImageSource, 0, nil) as Dictionary?
       if let dict = imageProperties as? [String: Any] {
        print(dict)
    }
  }

当我试图在设备上运行我的代码时,App崩溃。我认为问题是在转换,我试图做一些操作,但我不能转换我的UIImage类型的CFImageSource类型。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-26 13:51:12

不能将CIImage (或UIImage)转换为CGImageSource。若要创建CGImageSource,请执行以下操作:

代码语言:javascript
复制
guard let imageData = UIImageJPEGRepresentation(uiImage, 1)
    else { fatalError("Error getting image data") }

guard let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil)
    else { fatalError("Error creating image source") }

let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)

UIImageJPEGRepresentation将图像作为JPEG图像返回,所以uiImage最初采用的格式并不重要。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46427441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档