title: Getting a CGImage from CIImage
body: <p>I have a UIImage which is loaded from a CIImage with:</p>
  
  <p><code>tempImage = [UIImage imageWithCIImage:ciImage];</code></p>
  
  <p>The problem is I need to crop <code>tempImage</code> to a specific <code>CGRect</code> and the only way I know how to do this is by using <code>CGImage</code>. 
  The problem is that in the iOS 6.0 documentation I found this:</p>
  
  <p><strong>CGImage</strong><br>
  <code>If the UIImage object was initialized using a CIImage object, the value of the property is NULL.</code></p>
  
  <p>A. How to convert from CIImage to CGImage? 
  I'm using this code but I have a memory leak (and can't understand where):</p>
  
  <pre><code>+(UIImage*)UIImageFromCIImage:(CIImage*)ciImage {  
      CGSize size = ciImage.extent.size;  
      UIGraphicsBeginImageContext(size);  
      CGRect rect;  
      rect.origin = CGPointZero;  
      rect.size   = size;  
      UIImage *remImage = [UIImage imageWithCIImage:ciImage];  
      [remImage drawInRect:rect];  
      UIImage *result = UIGraphicsGetImageFromCurrentImageContext();  
      UIGraphicsEndImageContext();  
      remImage = nil;  
      ciImage = nil;  
      //
      return result;  
  }
  </code></pre>