Could somebody please explain or show some sample code of how I can use get a thumbnail to be put into a UIImageView after the user selects a photo with UIImagePickerController?
I've got it mostly figured out now. The difficulty I had was understanding Blocks, mostly the syntax of Blocks made it difficult to understand what they are and how they work.
In the delegate for the UIImagePickerController, when the user has selected an image, you can get the path to the picture in the assets library using:
NSURL *path = [info objectForKey:UIImagePickerControllerReferenceURL];
With that object, you can get the full size image or a thumbnail using the following code:
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref) {
// Gets the full size image
self.fullSizeImage = [UIImage imageWithCGImage:iref];
}
// Gets the thumbnail
self.thumbnail = [UIImage imageWithCGImage:[myasset thumbnail]];
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"in failureblock, got an error: %@",[myerror localizedDescription]);
};
ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];
[assetsLib assetForURL:urlForImage resultBlock:resultblock failureBlock:failureblock];
This page really helped me understand Blocks: Blocks in iOS 4
See also display image from URL retrieved from ALAsset in iPhone