如何解决如何获取从照片库或相机中选择的图像的路径?
这是我的图片选择代码
@IBAction func ProfilePicClicked(_ sender: UIButton) {
let imagePickercontroller = UIImagePickerController()
imagePickercontroller.delegate = self
let alert = UIAlertController(title: "Do You Want to Chage your Profile Picture?",message: "Choose any Option",preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Camera",style: .default,handler: { [self] (action:UIAlertAction) in
if UIImagePickerController.isSourceTypeAvailable(.camera){
imagePickercontroller.sourceType = .camera
self.present(imagePickercontroller,animated: true,completion: nil)
}else{
print("Camera not Available")
}
}))
alert.addAction(UIAlertAction(title: "Photo Library",handler: { (action:UIAlertAction) in
imagePickercontroller.sourceType = .photoLibrary
self.present(imagePickercontroller,completion: nil)
}))
self.present(alert,animated: true)
alert.addAction(UIAlertAction(title: "Cancel",style: .cancel,handler: nil))
}
func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
profilePicImageView.image = image
let imagePath = try! FileManager.default.url(for: .documentDirectory,in: .userDomainMask,appropriateFor: nil,create: true).appendingPathComponent("image.jpg")
print("Image path is \(imagePath)")
picker.dismiss(animated: true,completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true,completion: nil )
}
这是我选择图片的代码 我正在从用户那里获取图像并将图像设置为“profilePicImageView.image”
当用户选择图像时,我想确定其位置。 :https://i.stack.imgur.com/0K0Qs.png
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。