首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIImagePickerController的Xcode8.1和iOS 10.1.1“[通用]创建未知类型的图像格式是错误的”

UIImagePickerController的Xcode8.1和iOS 10.1.1“[通用]创建未知类型的图像格式是错误的”
EN

Stack Overflow用户
提问于 2016-12-07 07:18:10
回答 1查看 556关注 0票数 0

尝试允许用户从他们的照片库中选择一张照片,然后在UIImageView中显示该图像。图片库显示得很好,但是当我从我的图片库中选择一张照片时,我得到了这个错误:“通用地创建一个未知类型的图像格式是一个错误”。

逐步通过下面的代码,但错误只出现在选择一个图像时,这两个函数中的任何一个都没有发生。

代码语言:javascript
复制
@IBAction func openPhotoLibraryButton(sender: UIButton) {
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
        let imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
        imagePicker.allowsEditing = false
        self.present(imagePicker, animated: true, completion: nil)
    }
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {        
    let image = info[UIImagePickerControllerOriginalImage] as! UIImage!
    let imageData = UIImageJPEGRepresentation(image!, 0.6)
    let compressedJPGImage = UIImage(data: imageData!)
    imagePicked.image = compressedJPGImage
}

尝试了这里建议的解决方案:xCode 8 - Creating an image format with an unknown type is an error,但它们都不起作用,而且听起来好像有几个人没有解决这个问题。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2016-12-07 07:43:34

你有没有试过在picker之前添加_?我相信方法已经改变了,你正在使用的方法已经被弃用了,你应该能够让它自动补全。

代码语言:javascript
复制
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 
  if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
    if let imageData = UIImageJPEGRepresentation(image, 0.6) {
      let compressedJPGImage = UIImage(data: imageData)
      imagePicked.image = compressedJPGImage
    }
  } else {
    print("Image Picker Failure")
    //handle any possible image picker issues/failures so that app doesn't crash in the future
    //troubleshoot further if it always hits this
  }
  dismissViewControllerAnimated(true, completion: nil)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41006724

复制
相关文章

相似问题

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