So I am using below code to fetch all the images from library which is working fine :
func grabPhotos(){
let imgManager = PHImageManager.default()
let requestOptions = PHImageRequestOptions()
requestOptions.isSynchronous = true
requestOptions.deliveryMode = .highQualityFormat
let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
if let fetchResults : PHFetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions){
if fetchResults.count>0{
for i in 0..<fetchResults.count{
imgManager.requestImage(for: fetchResults.object(at: i), targetSize: CGSize(width:100, height: 100), contentMode: .aspectFill, options: requestOptions, resultHandler: {
image, error in
self.Galleryimages.append(image!)
print("array count is ",self.Galleryimages.count)
self.photoCollectionview.reloadData()
})
}
}
}
}
I am showing all the images in my UICollectionView, but I didn't find any way to get original image whenever clicking on any thumbnail image. I want to fetch the original image (full size image) when user clicks on any thumbnail image which is populated in UICollectionView.
Thank you.
You are resizing images when U fetch from PHAsset. So use
From this U can get original image with its original size. and for your collectionview you can direclty make thumbnail from it and display images. So when user taps on thumbnail, now you can show original image
Please use autoreleasepool for memory management.
To load thumbnail image.
Got the solution after doing too much stuff, may be it can help to others. Below are the steps to do this.
Step 1 : Declare object of PHFetchResult
Step 2 : Fetch results from gallery using below code:
}
Step 3 : Show the thumbnail images in your UI (collectionview/Tableview) using below code :
Step 4 : And finally get the full size image using below code.