问题
I am handling with the ALAssetsLibrary. When I get all the thumbnails, I just use the UIImageViews to hold the thumbnails and add them to the holder. Problem is here, it is really slow to add them. Maybe ten seconds or more. If there is much photos, it will be slower.
I would want to know what is the best practice to hold these thumbnails. (Many thanks!)
回答1:
Use AlAsset aspectRatioThumbnail
instead of fullResolutionImage
for high performance
The class ALAsset has two methods to get thumbnails:
- (CGImageRef)thumbnail
- (CGImageRef)aspectRatioThumbnail
example:
//ALAssetsLibrary block will execute in a separate thread. So I suggest to do the UI related stuff in main thread.
dispatch_sync(dispatch_get_main_queue(), ^{
CGImageRef iref = [myasset aspectRatioThumbnail];
itemToAdd.image = [UIImage imageWithCGImage:iref];
});//end block
回答2:
I think in this https://github.com/johnil/JFImagePickerController project with two classes JFAssetHelper and JFImageManager you will find answer.This use NSCache to cache photos and it really quick
来源:https://stackoverflow.com/questions/8116524/the-best-way-to-get-thumbnails-with-alassetslibrary