How to get image path from photo library and how to retrieve the image from photo library in iphone?

后端 未结 2 1805
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 02:12

I\'m new to iphone. In my small application, how to get image path from photo library. I use this following code to getting images and placed in imageview.

         


        
2条回答
  •  一个人的身影
    2020-12-16 03:09

    Swift 3.0, You can get imageData from referenceURL by following way

    let url = URL(string: "assets-library://asset/asset.JPG?id=1000000007&ext=JPG")
    let asset = PHAsset.fetchAssets(withALAssetURLs: [url], options: nil)
    guard let result = asset.firstObject else {
      return nil
    }
    let imageManager = PHImageManager.default()
    var imageData: Data? = nil
    imageManager.requestImageData(for: result, options: nil, resultHandler: { (data, string, orientation, dict) in
      imageData = data
    })
    

提交回复
热议问题