title: Losing image orientation while converting an image to CGImage
body: <p>I'm facing an image orientation issue when cropping a square portion of an image out of a rectangular original image. When image is in landscape, it's fine. But when it is in portrait, it seems that the image orientation is not preserved, which result in an image with wrong orientation AND bad crop:</p>
  
  <pre><code> func cropImage(cropRectangleCoordinates: CGRect) {
  
          let croppedImage = originalImage
  
          let finalCroppedImage : CGImageRef = CGImageCreateWithImageInRect(croppedImage.CGImage, cropRectangleCoordinates)
  
          finalImage =  UIImage(CGImage: finalCroppedImage)!
  
  
      }
  </code></pre>
  
  <p>I think the problem is with <code>croppedImage.CGImage</code>. Here the image gets converted to <code>CGImage</code>, but it seems not to preserve the orientation. 
  It's easy to preserve orientation by using <code>UIImage</code> only, but to make the crop, image needs to be temporarily <code>CGImage</code> and this is the problem. Even if I reorient the image when converting back to <code>UIImage</code>, it might be in the correct orientation but the damage is already done when cropping <code>CGImage</code>.</p>
  
  <p>This is a swift question, so please answer in swift, as the solution can be different in Objective-C.</p>