title: How to Load Photos Like the Photos App Does
body: <p>I've implemented my own custom <code>UIImagePickerController</code> which enables the user to access images from their photo libraries. Like the traditional <code>UIImagePickerController</code>, the user selects a photo from a list of thumbnails and the photo is then displayed on the next screen. I'm using the <code>ALAssets</code> library to accomplish this. </p>
  
  <p>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. </p>
  
  <p>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 <code>[ALAsset aspectRatioThumbnail]</code> feature: </p>
  
  <pre><code>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);
      });
  
  });
  </code></pre>
  
  <p>Problem with this code is that <code>aspectRatioThumbnail</code> only works for ios 5 or greater, plus I noticed that even with <code>aspectRatioThumbnail</code> there can be a small hiccup for larger images before they've been cached. </p>
  
  <p>So I've toyed around with using <code>[asset thumbnail]</code> 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).</p>
  
  <p>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 <code>[ALAssetRepresentation CGImageWithOptions]</code> might hold the answer?</p>