我正在處理ALAssetsLibrary。 當我得到所有的縮略圖時,我只是使用UIImageView來保存縮略圖並將其添加到持有人。 問題在這裏,添加它們真的很慢。也許十秒或更長時間。如果照片太多,會更慢。使用ALAssetsLibrary獲取縮略圖的最佳方式
我想知道持有這些縮略圖的最佳做法是什麼。 (非常感謝!)
我正在處理ALAssetsLibrary。 當我得到所有的縮略圖時,我只是使用UIImageView來保存縮略圖並將其添加到持有人。 問題在這裏,添加它們真的很慢。也許十秒或更長時間。如果照片太多,會更慢。使用ALAssetsLibrary獲取縮略圖的最佳方式
我想知道持有這些縮略圖的最佳做法是什麼。 (非常感謝!)
使用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
我覺得在這個https://github.com/johnil/JFImagePickerController項目中有兩個類JFAssetHelper和JFImageManager,你會發現答案。這個使用NSCache來緩存照片,這真的很快