请告诉我使用选择器视图获取图像路径的方法。
func addImage(sender: AnyObject){
picController.allowsEditing = false
picController.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(picController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
self.dismissViewControllerAnimated(true, completion: nil)
titleImageView.image = image
//Get the path of the image selected
// print(path)
}
我想打印图像的路径。 谢谢
答案 0 :(得分:1)
工作代码
func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){
self.titleImageView.image = image
let url: NSURL = editingInfo.valueForKey("UIImagePickerControllerReferenceURL") as! NSURL
print(url.absoluteString)
self.dismissViewControllerAnimated(true, completion: nil)
}
答案 1 :(得分:0)
您正在使用的UIImagePickerController
API通过委派提供对UIImage对象的引用。使用此UIImage引用,您可以将图像写入文件并使用该路径。要获得对库中图像资源的引用,您需要使用不同的委托回调:didFinishPickingMediaWithInfo
。只需从信息词典UIImagePickerControllerReferenceURL
获取路径。
有关详细信息,请参阅Apple的documentation。