title: Capture still UIImage without compression (from CMSampleBufferRef)?
body: <p>I need to obtain the <code>UIImage</code> from <strong>uncompressed</strong> image data from CMSampleBufferRef. I'm using the code:</p>
  
  <pre><code>captureStillImageOutput captureStillImageAsynchronouslyFromConnection:connection
   completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) 
  {
      // that famous function from Apple docs found on a lot of websites
      // does NOT work for still images
      UIImage *capturedImage = [self imageFromSampleBuffer:imageSampleBuffer]; 
  }
  </code></pre>
  
  <p><a href="http://developer.apple.com/library/ios/#qa/qa1702/_index.html" rel="nofollow noreferrer">http://developer.apple.com/library/ios/#qa/qa1702/_index.html</a> is a link to <code>imageFromSampleBuffer</code> function.</p>
  
  <p>But it does not work properly. :(</p>
  
  <p>There is a <code>jpegStillImageNSDataRepresentation:imageSampleBuffer</code> method, but it gives the compressed data (well, because JPEG). </p>
  
  <p>How can I get <code>UIImage</code> created with the most raw non-compressed data after capturing Still Image?</p>
  
  <p>Maybe, I should specify some settings to video output? I'm currently using those:</p>
  
  <pre><code>captureStillImageOutput = [[AVCaptureStillImageOutput alloc] init];
  captureStillImageOutput.outputSettings = @{ (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA) };
  </code></pre>
  
  <p>I've noticed, that output has a default value for <code>AVVideoCodecKey</code>, which is <code>AVVideoCodecJPEG</code>. Can it be avoided in any way, or <strong>does it even matter</strong> when capturing still image?</p>
  
  <p>I found something there: <a href="https://stackoverflow.com/questions/11612647/raw-image-data-from-camera-like-645-pro/">Raw image data from camera like &quot;645 PRO&quot;</a> , but I need just a UIImage, without using OpenCV or OGLES or other 3rd party.</p>