UIImagePickerController处理选择之后的图片

xcode10.1 用swift处理选择的相册。最后获得的键值对需要用这种方是取取得图片
info[UIImagePickerController.InfoKey.init(string:UIImagePickerControllerOriginalImage)]
下面是完整的代码
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
{
var selectedImage: UIImage?
if let editedImage = info[UIImagePickerController.InfoKey.init(string: UIImagePickerControllerEditedImage)] as? UIImage {
selectedImage = editedImage
self.bgImageView.image = selectedImage!
picker.dismiss(animated: true, completion: nil)
} else if let originalImage = info[UIImagePickerController.InfoKey.init(string:UIImagePickerControllerOriginalImage)] as? UIImage {
selectedImage = originalImage
self.bgImageView.image = selectedImage!
picker.dismiss(animated: true, completion: nil)
}
print(info)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController){
self.dismiss(animated: true, completion: nil)
}

你可能感兴趣的:(UIImagePickerController处理选择之后的图片)