This code is extracted from some ELCImagePickerController example from here . Some changes have been made to simplify.
May it help you
[self.assetGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { if(result == nil) return; UIImageView *assetImageView = [[UIImageView alloc] initWithFrame:viewFrames]; [assetImageView setContentMode:UIViewContentModeScaleToFill]; [assetImageView setImage:[UIImage imageWithCGImage:[result thumbnail]]]; }];
Happy coding :)
NEW RESPONSE
Just use
[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]
to store the image directly instead of storing the asset while storing the asset in assetsp
properly
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) { if(result != nil) { if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) { [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]]; NSLog(@"result is:%@",result); NSLog(@"asset URLDictionary is:%@",assetURLDictionaries); NSURL *url= (NSURL*) [[result defaultRepresentation]url]; [library assetForURL:url resultBlock:^(ALAsset *asset) {
NEW ANSWER 1
Try this code to store ALAsset data in a mutable array
NSMutableArray *returnArray = [[NSMutableArray alloc] init]; for(ALAsset *asset in _assets) { NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init]; [workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:@"UIImagePickerControllerMediaType"]; [workingDictionary setObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]] forKey:@"UIImagePickerControllerOriginalImage"]; [workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:@"UIImagePickerControllerReferenceURL"]; [returnArray addObject:workingDictionary];
and get the image in a UIImageView, just do it
NSDictionary *dict = [info objectAtIndex:i]; UIImageView *imageview = [[UIImageView alloc] initWithImage:[dict objectForKey:UIImagePickerControllerOriginalImage]]; [imageview setContentMode:UIViewContentModeScaleAspectFit];
source share