简体   繁体   English

我要使用哪种方式从照片库加载图像?

[英]which way do i use for loading image from photo library?

I had watched a few tutorial for loading image from photo library to tableView cell. 我看过一些教程,将照片从照片库加载到tableView单元中。

The way they are doing that is little bit odd because they use UIImagePickerController get the image from the photo library, create path for it and save it to NS User Default or CoreData. 他们这样做的方式有点奇怪,因为他们使用UIImagePickerController从照片库获取图像,为其创建路径并将其保存到NS User Default或CoreData。

So is there a way to retrieve the image path from the photo library and load it directly? 那么有没有办法从照片库中检索图像路径并直接加载呢?

You can use this code. 您可以使用此代码。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM