title: iPhone: Get camera preview
body: <p>I'd like to get the image that is being displayed on the UIImagePickerController when user  uses the camera. And when I get I want to process the image and display instead of regular camera view.</p>
  
  <p>But the problem is when I want to get the camera view, the image is just a black rectangle.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>UIView *cameraView = [[[[[[imagePicker.view subviews] objectAtIndex:0]
                           subviews] objectAtIndex: 0]
                         subviews] objectAtIndex: 0];
  
  UIGraphicsBeginImageContext( CGSizeMake(320, 427) );
  [cameraView.layer renderInContext: UIGraphicsGetCurrentContext()];
  UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  
  imageToDisplay.image = [PixelProcessing processImage: viewImage];   //In this case the image is black
  //imageToDisplay.image = viewImage; //In this case the image is black too
  //imageToDisplay.image = [UIImage imageNamed: @"icon.png"];     //In this case image is being displayed properly
  </code></pre>
  
  <p>What am I doing wrong?</p>
  
  <p>Thanks.</p>