创建具有未知类型的图像格式是swift中的错误,请检查我的下面的代码

时间:2017-08-18 10:25:25

标签: ios swift3

我从照片库中选择照片,无法在桌面视图中显示照片。            我得到了错误:  [Generic]创建具有未知类型的图像格式是错误

extension EditProfileViewController: GMPickerDelegate {

    func gmPicker(_ gmPicker: GMPicker, didSelect string: String) {
        self.genderStr = string
        self.tableView.reloadData()
    }

    func gmPickerDidCancelSelection(_ gmPicker: GMPicker) {

    }

    fileprivate func setupPickerView() {

        picker.delegate = self
        picker.config.animationDuration = 0.5

        picker.config.cancelButtonTitle = "Cancel"
        picker.config.confirmButtonTitle = "Confirm"

        picker.config.contentBackgroundColor = UIColor(red: 253/255.0, green: 253/255.0, blue: 253/255.0, alpha: 1)
        picker.config.headerBackgroundColor = UIColor(red: 244/255.0, green: 244/255.0, blue: 244/255.0, alpha: 1)
        picker.config.confirmButtonColor = UIColor.black
        picker.config.cancelButtonColor = UIColor.black

    }

}

class EditProfileViewController: UIViewController, UITableViewDelegate, UITableViewDataSource,UIPickerViewDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate{
    var picker      = GMPicker()
    let pickerBgView = UIView(frame: CGRect(x: 0,y: 0,width: 30,height: 250))
    var pickerView = UIPickerView()
    var addressRecord = [String]()

    var image1 = UIImage()
    let imagePicker: UIImagePickerController! = UIImagePickerController()

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(UINib(nibName: "RoundImgCell", bundle: nil), forCellReuseIdentifier: "CellImg")
        pickerView.frame =  CGRect(x: 0,y: -20,width: self.view.frame.width,height: 250)//UIPickerView(frame: CGRectMake(0,20,self.view.frame.width,250))
        pickerView.delegate = self

        pickerBgView.backgroundColor = UIColor.yellow

        let toolbar = UIToolbar(frame: CGRect(x: 0,y: 0,width: self.view.frame.width,height: 40))
        toolbar.barStyle = .black

        let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.done, target: self, action: #selector(EditProfileViewController.doneAction))
        doneButton.tintColor = UIColor.white

        let space = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: #selector(EditProfileViewController.doneAction))
        let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.done, target: self, action: #selector(EditProfileViewController.cancelAction))
        cancelButton.tintColor = UIColor.white
        pickerBgView.addSubview(toolbar)
        pickerBgView.addSubview(pickerView)
        toolbar.setItems([doneButton,space,cancelButton], animated: true)

        imagePicker.delegate = self

    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return self.addressRecord.count

    }
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return self.addressRecord[row]
    }
    public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        if indexPath.row == 0 {

            uploadImageMethod()

        }
    }
    func uploadImageMethod() {

        let actionSheetController: UIAlertController = UIAlertController(title: "Action Sheet", message: "Now! Choose an option!", preferredStyle: .actionSheet)
        let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .cancel) { action -> Void in
            //Just dismiss the action sheet
        }
        actionSheetController.addAction(cancelAction)
        //Create and add first option action
        let takePictureAction: UIAlertAction = UIAlertAction(title: "Take Picture", style: .default) { action -> Void in
            if (UIImagePickerController.isSourceTypeAvailable(.camera)) {
                if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
                    self.imagePicker.allowsEditing = false
                    self.imagePicker.sourceType = .camera
                    self.imagePicker.delegate = self
                    self.imagePicker.cameraCaptureMode = .photo
                    self.present(self.imagePicker, animated: true, completion: {})
                } else {
                    print("Rear camera doesn't exist.")
                }
            } else if (UIImagePickerController.isSourceTypeAvailable(.photoLibrary)) {
                self.imagePicker.sourceType = .photoLibrary
                self.imagePicker.delegate = self
                self.present(self.imagePicker, animated: true, completion: {})
            }
        }
        actionSheetController.addAction(takePictureAction)
        //Create and add a second option action
        let choosePictureAction: UIAlertAction = UIAlertAction(title: "Choose From Camera Roll", style: .default) { action -> Void in
            self.imagePicker.sourceType = .photoLibrary
            self.imagePicker.delegate = self
            self.present(self.imagePicker, animated: true, completion: {})


        }
        actionSheetController.addAction(choosePictureAction)

        //Present the AlertController
        self.present(actionSheetController, animated: true, completion: nil)
    }

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        print("select below")
        if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            //imagePost.image = image //updated
            // image1.image = image
            print("picked")
            print(image)


        } else{
            print("Something went wrong")
        }

        self.dismiss(animated: true, completion: nil)
    }

}

错误:

Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x12140acc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices 
One of the two will be used. Which one is undefined.
[Generic] Creating an image format with an unknown type is an error

0 个答案:

没有答案