首页 > 解决方案 > 我怎样才能让这个 imagePickerController 能够接受编辑的图像?

问题描述

我怎样才能让这个 imagePickerController 能够接受编辑的图像?

选择图像并对其进行调整(放大和缩小)并选择完成时,图像将恢复到其原始状态。我可以在我的代码中添加什么来保存缩放图像并显示在我的图像视图中?

到目前为止,以下是我的代码:

let cameraRollAction = UIAlertAction(title: "Camera Roll", style: .default) { (action) in
    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
        let picker = UIImagePickerController()
        picker.delegate = self
        picker.allowsEditing = true
        picker.mediaTypes = [kUTTypeImage as String]
        picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
        self.present(picker, animated: true, completion: nil)
        self.newPic = false
    }

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    let mediaType = info[UIImagePickerControllerMediaType] as! NSString
    if mediaType.isEqual(to: kUTTypeImage as String) {
        let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
        profileImageView.image = selectedImage
        if newPic == true {
            UIImageWriteToSavedPhotosAlbum(selectedImage, self, #selector(imageError), nil)
        }
    }
    self.dismiss(animated: true, completion: nil)
}

标签: swiftuiimagepickercontroller

解决方案


代替

UIImagePickerControllerOriginalImage

采用

UIImagePickerControllerEditedImage

推荐阅读