Swift,如何在iOS中获取UIPickerView的图片路径?
Swift, How to get the image path from UIPickerView in iOS?
在 Android 中,有一种方法可以获取 selected 图像路径并将其显示在我们的应用程序中。有什么方法可以在 iOS 中做同样的事情吗?要 select 选择器视图中的图像,获取图像路径并显示在我的应用程序中?
UIImagePickerControllerOriginalImage
returns 仅图像数据,不引用其本地存储。
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
}
}
如需更多帮助,请参阅此
委托回调didFinishPickingMediaWithInfo
。只需从信息字典的 UIImagePickerControllerReferenceURL
.
中获取路径即可
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)
}
在 Android 中,有一种方法可以获取 selected 图像路径并将其显示在我们的应用程序中。有什么方法可以在 iOS 中做同样的事情吗?要 select 选择器视图中的图像,获取图像路径并显示在我的应用程序中?
UIImagePickerControllerOriginalImage
returns 仅图像数据,不引用其本地存储。
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
}
}
如需更多帮助,请参阅此
委托回调didFinishPickingMediaWithInfo
。只需从信息字典的 UIImagePickerControllerReferenceURL
.
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)
}