屏幕上的 150x150 图像 1-3mb 文件大小,这些是 ios 相机拍摄的照片。
这是我加快速度的两个建议。
建议一
该ALAssetsLibrary
库将在单独的线程上运行。我建议在主线程中做 UI 相关的事情。使用-performSelectorOnMainThread:
或dispatch_sync(dispatch_get_main_queue()
在ALAssetsLibrary
块内将解决您的问题。
例子:
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *needToStop) {
dispatch_sync(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageWithCGImage:result.defaultRepresentation.fullScreenImage];
//do UI stuff here.
}); }]; }
failureBlock:^(NSError *error) {
NSLog(@"%@",error.description);
}];
或者
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *needToStop) {
UIImage *image = [UIImage imageWithCGImage:result.defaultRepresentation.fullScreenImage];
[self performSelectorOnMainThread:@selector(usePhotolibraryimage:) withObject:image waitUntilDone:NO];
}]; }
failureBlock:^(NSError *error) {
NSLog(@"%@",error.description);
}];
- (void)usePhotolibraryimage:(UiImage *)myImage{
//do UI stuf here.
}
建议二
使用 AlAssetaspectRatioThumbnail
代替fullResolutionImage
高性能
dispatch_sync(dispatch_get_main_queue(), ^{
CGImageRef iref = [myasset aspectRatioThumbnail];
//CGImageRef iref = [myasset thumbnail];
UIImage *image = [UIImage imageWithCGImage:iref];
});