【发布时间】:2011-11-14 02:01:45
【问题描述】:
我正在处理 ALAssetsLibrary。 当我得到所有缩略图时,我只是使用 UIImageViews 来保存缩略图并将它们添加到持有人。 问题就在这里,添加它们真的很慢。也许十秒钟或更长时间。照片多的话会比较慢。
我想知道保存这些缩略图的最佳做法是什么。 (非常感谢!)
【问题讨论】:
我正在处理 ALAssetsLibrary。 当我得到所有缩略图时,我只是使用 UIImageViews 来保存缩略图并将它们添加到持有人。 问题就在这里,添加它们真的很慢。也许十秒钟或更长时间。照片多的话会比较慢。
我想知道保存这些缩略图的最佳做法是什么。 (非常感谢!)
【问题讨论】:
使用 AlAsset aspectRatioThumbnail 代替 fullResolutionImage 以获得高性能
ALAsset 类有两种获取缩略图的方法:
- (CGImageRef)thumbnail
- (CGImageRef)aspectRatioThumbnail
示例:
//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
【讨论】:
我认为在这个有两个类 JFAssetHelper 和 JFImageManager 的 https://github.com/johnil/JFImagePickerController 项目中你会找到答案。这使用 NSCache 来缓存照片,它真的很快
【讨论】: