Question

I need to get the latest 10 photos from the library and display them. How can I get UIImages with those photos?

I tried UIImagePickerController but I think this isn't possible with it.

Was it helpful?

Solution

Use ALAssests! For example...

Update: 04/27/14

- (void)loadImageFromIndex:(int)index withAssetLibrary:(ALAssetsLibrary*)library {

[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
    // Within the group enumeration block, filter to enumerate your photos.
    [group setAssetsFilter:[ALAssetsFilter allPhotos]];

    //if index exceeds bounds, kill the method
    if (index < 0 || index > [group numberOfAssets]-1) {
        return;
    }

    // Chooses the photo at the index
    [group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:index] options:0 usingBlock:^(ALAsset *alAsset, NSUInteger inde, BOOL *innerStop) {
        // The end of the enumeration is signaled by asset == nil.

        if (alAsset) {
            ALAssetRepresentation *representation = [alAsset defaultRepresentation];
            UIImage *tempImage = [UIImage imageWithCGImage:[representation fullScreenImage]];

            // Do something with the image

            }
        }];
    }

    failureBlock: ^(NSError *error) {
        NSLog(@"None");
    }];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top