简体   繁体   中英

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.

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.

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中使用相同的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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