Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Images from Saved Images programaically in iphone WITHOUT UImagePickerController?

Tags:

xcode

ios

iphone

I know how to let user select an image from UIImagePickerController, but I don't want that. I just want to have NSArray of images stored in the phone, but I don't want to involve user (to select a one and then have that image...),rather, I have created my own custom Image selector controller and want to have source as the gallary.

like image 671
Sunil Chauhan Avatar asked Mar 16 '12 12:03

Sunil Chauhan


People also ask

How do I take pictures without metadata on iPhone?

Remove Photo EXIF Data (iOS)Install the Metadata Remover EXIF GPS TIFF app from the App Store on your device. Launch the app, select your photos, tap on the settings icon at the bottom-left corner, and select clear all metadata.

What metadata is stored in iPhone images?

Metadata or EXIF data usually includes the following information: iPhone model, camera type. Camera settings – ISO, shutter, focal length, lens, aperture. Image Information – Format, file size, date and time, resolution.


1 Answers

You can easily do that using the AVFoundation and AssetsLibrary framework. Here is the code to access all the photos:

-(void)addPhoto:(ALAssetRepresentation *)asset
{
    //NSLog(@"Adding photo!");
    [photos addObject:asset];
}

-(void)loadPhotos
{
    photos = [[NSMutableArray alloc] init];    
    library = [[ALAssetsLibrary alloc] init];    

    // Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
    if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
        {        
             // Within the group enumeration block, filter if necessary
             [group setAssetsFilter:[ALAssetsFilter allPhotos]];           
             [group enumerateAssetsUsingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop)
              {                                 
                  // The end of the enumeration is signaled by asset == nil.            
                  if (alAsset)
                  {
                      ALAssetRepresentation *representation = [alAsset defaultRepresentation];                      
                      [self addPhoto:representation];                      
                  }       
                  else
                  {
                      NSLog(@"Done! Count = %d", photos.count);
                      //Do something awesome
                  }
              }];
         }
         failureBlock: ^(NSError *error) {
         // Typically you should handle an error more gracefully than this.
         NSLog(@"No groups");                                 
         }];
    }
}
like image 150
Bob de Graaf Avatar answered Oct 24 '22 09:10

Bob de Graaf