我使用以下代码从照片库中获取图像,在显示它之前调整它的大小正在接收内存警告。它也因内存压力而终止。
-(void)readImages:(int)getAlbumImages
{
imagesArray = [[NSMutableArray alloc]init];
allImagesArray = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
[allImagesArray addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[imagesArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
[picsTbl reloadData];
[loadingView setHidden:YES];
}
failureBlock:^(NSError *error){ NSLog(@"test:Fail"); } ];
}
}
else if(result == NULL){
[loadingView setHidden:YES];
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
NSLog(@"Number of assets in group :%ld",(long)[group numberOfAssets]);
NSLog(@"asset group is:%@",assetGroups);
}
NSLog(@"[group numberOfAssets] %d",[group numberOfAssets]);
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(@"A problem occurred");}];
}
请帮忙。