从图书馆获取最新的十张照片

时间:2014-04-21 19:08:00

标签: ios uiimage photo

我需要从图书馆获取最新的10张照片并进行显示。如何使用这些照片获取UIImage个?

我试过UIImagePickerController,但我认为这是不可能的。

1 个答案:

答案 0 :(得分:0)

使用ALAssests!例如......

更新:2014年4月27日

- (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");
    }];
}