Skip to content

Instantly share code, notes, and snippets.

@ideamonk
Forked from debuggerman/ALAssetUsage.m
Created April 17, 2012 23:38
Show Gist options
  • Save ideamonk/2409923 to your computer and use it in GitHub Desktop.
Save ideamonk/2409923 to your computer and use it in GitHub Desktop.
using AssetsLibrary to read saved images album in iOS
void (^assetEnumerator)(ALAsset* result, NSUInteger index, BOOL*);
void (^groupEnumerator)(ALAssetsGroup*, BOOL *);
void (^faliure)(NSError*);
groupEnumerator = ^(ALAssetsGroup *group, BOOL *stop){
[group enumerateAssetsUsingBlock:assetEnumerator];
};
assetEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop){
CGImageRef image = [result thumbnail];
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:image]];
CGRect frame = [iv frame];
frame.origin.x = x;
frame.origin.y = y;
frame.size.width= 30;
frame.size.height = 30;
[iv setFrame:frame];
x = x + 40;
if (x>320) {
x=0;
y += 40;
}
//add to whatever view you are in
[self.window addSubview:iv];
};
faliure = ^(NSError *error){ NSLog(@"Failed"); };
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:groupEnumerator
failureBlock:faliure];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment