The best way to get thumbnails with ALAssetsLibrary

送分小仙女□ 提交于 2020-01-02 07:19:14

问题


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

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