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

纵然是瞬间 提交于 2019-11-27 22:21:24
Phlibbo

UIImagePickerControllerOriginalImage returns only the image's data, with no reference to its local storage. I haven't used it myself but I guess what you are looking for is

NSURL* localUrl = (NSURL *)[info valueForKey:UIImagePickerControllerReferenceURL];

At least, it's the only way I know of to retrieve any URL.

To retrieve the image, have a look at this question. But also keep in mind, that you already have the image retrieved with

UIImage* image=(UIImage*)[info objectForKey:@"UIImagePickerControllerOriginalImage"];

so ask yourself if you really need this.

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
})

There's no way you can get the path of the photos from photoLibrary.

But you can retrieve the photos from photoLibrary. Just use UIImagePickerControllerSourceTypePhotoLibrary instead of UIImagePickerControllerSourceTypeSavedPhotosAlbum.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!