150x150 images on screen 1-3mb file size, these are photos taken by
ios camera.
Here are my two suggestions to speed it up.
Suggestion 1
The ALAssetsLibrary
library will run on a separate thread. I propose to do the UI related stuff in main thread. Usage of -performSelectorOnMainThread:
or dispatch_sync(dispatch_get_main_queue()
inside the ALAssetsLibrary
block will resolve your issue.
Example:
[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);
}];
or
[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.
}
Suggestion 2
Use AlAsset aspectRatioThumbnail
instead of fullResolutionImage
for high performance
dispatch_sync(dispatch_get_main_queue(), ^{
CGImageRef iref = [myasset aspectRatioThumbnail];
//CGImageRef iref = [myasset thumbnail];
UIImage *image = [UIImage imageWithCGImage:iref];
});