在Android中,有一种方法可以获取所选的图像路径并在我们的应用中显示它。在iOS中有什么方法可以做同样的事情吗?要从选择器视图中选择图像,请拍摄图像路径并在我的应用程序中显示?
答案 0 :(得分:1)
委派回电 didFinishPickingMediaWithInfo
。只需从信息词典UIImagePickerControllerReferenceURL
获取路径。
答案 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