如何获取从照片库或相机中选择的图像的路径?

问题描述

这是我的图片选择代码

@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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...