title: Replacing UIImageJPEGRepresentation with UIGraphicsImageRenderer's jpegData
body: <p>I am working to add support for wide color photos in iOS 10. When the user takes a photo from the camera, I need to use the new API that supports the new color space to save the photo data - <code>UIGraphicsImageRenderer</code>'s <code>jpegData</code> instead of <code>UIImageJPEGRepresentation</code>. </p>
  
  <p>I'm running into some troubles with image orientations. Taking a photo on my iPad in portrait, the image isn't being drawn correctly. See the comments below:</p>
  
  <p>Old API:</p>
  
  <pre><code>let image = info[UIImagePickerControllerOriginalImage] as! UIImage
  let imageData = UIImageJPEGRepresentation(image, 1)
  </code></pre>
  
  <p>New API:</p>
  
  <pre><code>let image = info[UIImagePickerControllerOriginalImage] as! UIImage
  let cgImage = image.cgImage!
  let ciImage = CIImage(cgImage: cgImage)
  
  let format = UIGraphicsImageRendererFormat()
  format.scale = 1
  format.prefersExtendedRange = true
  
  let renderer = UIGraphicsImageRenderer(bounds: ciImage.extent, format: format)
  let imageData = renderer.jpegData(withCompressionQuality: 1, actions: { context in
      context.cgContext.draw(cgImage, in: ciImage.extent) //draws flipped horizontally
      //image.draw(at: .zero) //draws rotated 90 degrees leaving black at bottom
      //image.draw(in: ciImage.extent) //draws rotated 90 degrees stretching and compressing the image to fill the rect 
   })
  </code></pre>
  
  <p>What's the correct way to replace <code>UIImageJPEGRepresentation</code> with <code>UIGraphicsImageRenderer</code>'s <code>jpegData</code>?</p>