Swift,如何从iOS中的UIPickerView获取图像路径?

时间:2016-08-29 04:06:53

标签: ios swift uiimagepickercontroller

在Android中,有一种方法可以获取所选的图像路径并在我们的应用中显示它。在iOS中有什么方法可以做同样的事情吗?要从选择器视图中选择图像,请拍摄图像路径并在我的应用程序中显示?

3 个答案:

答案 0 :(得分:1)

委派回电 didFinishPickingMediaWithInfo。只需从信息词典UIImagePickerControllerReferenceURL获取路径。

more check apple documentation

答案 1 :(得分:1)

func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!)
{

 self.displayImg.image = image

    let imgURL: NSURL = editingInfo.valueForKey("UIImagePickerControllerReferenceURL") as! NSURL

    print(imgURL.absoluteString)

    self.dismissViewControllerAnimated(true, completion: nil)
}

答案 2 :(得分:0)

UIImagePickerControllerOriginalImage仅返回图片的数据,不会引用其本地存储空间。

 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

     if let localUrl = (info[UIImagePickerControllerMediaURL] ?? info[UIImagePickerControllerReferenceURL]) as? NSURL {

        print (localUrl)
        //if you want to get the image name 
        let imageName = localUrl.path!.lastPathComponent
     }    
 }

获取更多帮助,请参阅此link