[英]which way do i use for loading image from photo library?
我看过一些教程,将照片从照片库加载到tableView单元中。
他们这样做的方式有点奇怪,因为他们使用UIImagePickerController从照片库获取图像,为其创建路径并将其保存到NS User Default或CoreData。
那么有没有办法从照片库中检索图像路径并直接加载呢?
您可以使用此代码。
class MyViewController {
func getImage() {
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .PhotoLibrary
imagePickerController.delegate = self
self.presentViewController(imagePickerController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
// Use image here.
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
self.dismissViewControllerAnimated(true, completion: nil)
}
}
您可以尝试ALAssetRepresentation,我在Obj-C中使用相同的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.