I before blogged my experience in fetching out the image off Assets in iPhone. I could find even more a better solution that i used in my project. Let me share that thru this short blog.
ALAssetsLibrary
*library = [[ALAssetsLibrary
alloc]
init];
NSAutoreleasePool
*pool = [[NSAutoreleasePool
alloc]init];
void
(^assetEnumerator)(ALAsset
*, NSUInteger,
BOOL
*) = ^(ALAsset
*result, NSUInteger
index, BOOL
*stop)
{
NSMutableDictionary
*photoDic = [NSMutableDictionary
dictionary];
if(result
!= NULL)
{
NSArray
*arrKeys = [[result valueForProperty:ALAssetPropertyURLs]allKeys];
if([[result
valueForProperty:ALAssetPropertyType]isEqualToString:ALAssetTypePhoto])
{
NSString
*imageName = [[result defaultRepresentation]filename];
NSURL*
photoUrl = [[result
valueForProperty:ALAssetPropertyURLs]objectForKey:[arrKeys
objectAtIndex:0]];
UIImage
*Image = [UIImage
imageWithCGImage:[[result
defaultRepresentation]
fullScreenImage]];
UIImage
*ThumbnailImage = [UIImage
imageWithCGImage:[result
thumbnail]];
}
}
};
void
(^assetGroupEnumerator)(ALAssetsGroup
*, BOOL
*) = ^(ALAssetsGroup
*group, BOOL
*stop)
{
if(group
!= nil)
{
[group
enumerateAssetsUsingBlock:assetEnumerator];
}
};
[library
enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError
*error){
NSLog(@"%@",error);
}];
[pool
release];
You get the image and the thumb image from the above code.
Happy blogging :)
No comments:
Post a Comment