title: NSData to UIImage
body: <p>I'm trying to save a UIIMage and then retrieve it and display it. I've been successful by saving an image in the bundle, retrieving it from there and displaying. My problem comes from when I try to save an image to disk (converting it to NSData), then retrieving it. I convert the image to NSData like so... </p>
  
  <pre><code>NSData* topImageData = UIImageJPEGRepresentation(topImage, 1.0);
  </code></pre>
  
  <p>then I write it to disk like so...</p>
  
  <pre><code>[topImageData writeToFile:topPathToFile atomically:NO];
  </code></pre>
  
  <p>then I tried to retrieve it like so...</p>
  
  <pre><code>topSubView.image = [[UIImage alloc] initWithContentsOfFile:topPathToFile];
  </code></pre>
  
  <p>which returns no image (the size is zero). so then I tried...</p>
  
  <pre><code>NSData *data = [[NSData alloc] initWithContentsOfFile:topPathToFile];
  topSubView.image = [[UIImage alloc] initWithData:data];
  </code></pre>
  
  <p>to no avail. When I step through the debugger I do see that data contains the correct number of bytes but I'm confused as to why my image is not being created. Am I missing a step? Do I need to do something with NSData before converting to an image?</p>