I've implemented my own custom UIImagePickerController
which enables the user to access images from their photo libraries. Like the traditional UIImagePickerController
, the user selects a photo from a list of thumbnails and the photo is then displayed on the next screen. I'm using the ALAssets
library to accomplish this.
The problem I'm trying to solve is how to load the image like the photos app does after its thumbnail has been selected. Larger sized photos can take a while to load, thus causing a little hiccup and making the transition very unsmooth.
It appears the photos app loads a thumbnail of the image initially, then updates with the full image once it's finished loading. I've been able to accomplish this with the following code using the [ALAsset aspectRatioThumbnail]
feature:
UIImageView *imageViewTemp = [[UIImageView alloc] initWithImage: [UIImage imageWithCGImage:[self.asset aspectRatioThumbnail]]];
[self setImageView: imageViewTemp];
[[self scrollView] addSubview:[self imageView]];
[[self scrollView] setContentSize: [self.imageView.image size]];
[self setMaxMinZoomScalesForCurrentBounds];
[[self scrollView] setZoomScale: [[self scrollView] minimumZoomScale]];
[imageViewTemp release];
dispatch_async(dispatch_get_global_queue(0, 0), ^
{
CGImageRef imageRef = CGImageCreateCopy(self.asset.defaultRepresentation.fullScreenImage);
dispatch_async(dispatch_get_main_queue(), ^
{
UIImage *image = [[UIImage imageWithCGImage: imageRef] retain];
[[self imageView] setImage: image];
[image release];
CGImageRelease(imageRef);
});
});
Problem with this code is that aspectRatioThumbnail
only works for ios 5 or greater, plus I noticed that even with aspectRatioThumbnail
there can be a small hiccup for larger images before they've been cached.
So I've toyed around with using [asset thumbnail]
however the problem with this is the thumbnail that returns is square, so it looks funny when you load in the real image. I've tried finding some ways to get the dimension of the full sized image so I can stretch it, but it doesn't seem like there is a great way of doing this (http://stackoverflow.com/questions/10067765/alasset-image-size).
So I'm just wondering if anyone knows of anyway to do this that'll work for ios4 and above and work pretty smoothly. Possible that [ALAssetRepresentation CGImageWithOptions]
might hold the answer?