簡體   English   中英

我要使用哪種方式從照片庫加載圖像?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM