在Swift 3/4中获取EXIF信息时出错 [英] Error getting EXIF information in Swift 3/4

查看:76
本文介绍了在Swift 3/4中获取EXIF信息时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的PhotoLibrary中的图像中获取EXIF数据,但是找不到正确的方法.我使用了此问题

I want to get EXIF data from images in my PhotoLibrary but cannot find the correct method. I have used answers from this question, and this one. I'm getting the following console output:

imageSource:  <UIImage: 0x6080000b8a20> size {3000, 2002} orientation 0 scale 1.000000
2017-09-18 11:24:28.513567+0300 PhotoTest[10581:6526935] CGImageSourceCopyPropertiesAtIndex:3517: *** ERROR: CGImageSourceCopyPropertiesAtIndex: source is not a CGImageSourceRef
2017-09-18 11:24:29.071412+0300 PhotoTest[10581:6527417] [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

这是我当前的代码尝试.我将不胜感激任何解决方案或想法.我一直想尝试各种方法,但我对 imageIO 的了解不足以解决问题.

This is my current code attempt. I'd appreciate any solutions or ideas. I've been scratching my head trying to divine various methods, but I don't know enough about imageIO to solve the problem.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    self.dismiss(animated: true, completion: nil)

    let bigImage = info[UIImagePickerControllerOriginalImage] as? UIImage
    photoImageView.image = bigImage

     imageData = UIImagePNGRepresentation(bigImage!) as NSData?


    if let imageSource = info[UIImagePickerControllerOriginalImage] {
         print("imageSource: ", imageSource)

        let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource as! CGImageSource, 0, nil)


         //print("imageProperties: ", imageProperties!)
        if let dict = imageProperties as? [String: Any] {
            print(dict)
        }
    }

    dismiss(animated: true, completion: nil)
}

推荐答案

您正在看到:

*** ERROR: CGImageSourceCopyPropertiesAtIndex: source is not a CGImageSourceRef

行,因为您需要通过 CGImageSourceCreate ... API之一来创建 imageSource .

line because you need to create your imageSource via one of the CGImageSourceCreate... API's.

尝试这样做:

    if let bigImage = info[UIImagePickerControllerOriginalImage] as? UIImage
    {
        if let imageData = UIImagePNGRepresentation(bigImage)
        {
            if let imageSource = CGImageSourceCreateWithData(imageData as CFData, nil)
            {
                print("imageSource: ", imageSource)

                let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)

                //print("imageProperties: ", imageProperties!)
                if let dict = imageProperties as? [String: Any] {
                    print(dict)
                }
            }
        }
    }

这篇关于在Swift 3/4中获取EXIF信息时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆