我需要在设备照片库中找到照片的位置。为此,我试图加载图像的Exif数据。这是我的密码:
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类型。
发布于 2017-09-26 13:51:12
不能将CIImage (或UIImage)转换为CGImageSource。若要创建CGImageSource,请执行以下操作:
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最初采用的格式并不重要。
https://stackoverflow.com/questions/46427441
复制相似问题