Friday, April 5, 2013

Get images from photolibrary using ALAsset.... IOS


- (void)getImagesFromPhotoLibrary{ 
void (^assetsEnumeration)(ALAsset *,NSUInteger,BOOL *) = ^(ALAsset *asset,NSUInteger index,BOOL *stop){
        
        if(asset!=nil)
        {
            NSLog(@"obtained Asset %@",[asset valueForProperty:ALAssetPropertyURLs]);
            
            [self.dataContainer addObject:asset];
            NSLog(@"assest...%@",asset);
             [self setImage];
             
        }
       NSLog(@"data container...%@",self.dataContainer); 
    };
    
    void (^assetsGroupEnumeration)(ALAssetsGroup *,BOOL *) = ^(ALAssetsGroup *group,BOOL *status){
        
        if(group!=nil)
        {
            [group enumerateAssetsUsingBlock:assetsEnumeration];
        }
        
    };
    // allocate the library
    library = [[ALAssetsLibrary alloc]init];
    
    [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetsGroupEnumeration failureBlock:^(NSError *error) {
        NSLog(@"Error :%@", [error localizedDescription]);
    }];
}



Set Image:-
    [imageview.image setImage:[UIImage imageWithCGImage:[(ALAsset*)[dataContainer objectAtIndex:indexPath ]thumbnail]]];

4 comments:

  1. it have retrive only thumbnail of the image how to get the original image.

    ReplyDelete
    Replies
    1. Hello Friend
      Here i m sharing code of getting original image from library :-

      ALAssetRepresentation *rep = [[dataContainer objectAtIndex:indexPath+1] defaultRepresentation];
      CGImageRef iref = [rep fullResolutionImage];
      if (iref) {
      UIImage *image = [UIImage imageWithCGImage:iref];
      }

      Delete
  2. You've made some good points there. I looked on the web to find out moree about the issue and found most individuals
    will go along with your views on thiss website.


    Take a look at my homepage :: Beats By Dre Wireless

    ReplyDelete
  3. I am sure this article has touched all the internet visitors,
    itts really really fastidious piece off writing on building up new webpage.


    my web-site - beats bby dr dre white (http://keylimeshop.com/outlet?beats=beats-by-dr-dre-white.php)

    ReplyDelete