title: UIImage from a region of UIView
body: <p>I'm trying to clip a region of an <code>UIView</code>, into a <code>UIImage</code> for later reuse.</p>
  
  <p>I've worked out this code from some snippets:</p>
  
  <pre><code> CGRect _frameIWant = CGRectMake(100, 100, 100, 100);
  
   UIGraphicsBeginImageContext(view.frame.size);
   [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  
   //STEP A: GET AN IMAGE FOR THE FULL FRAME
   UIImage *_fullFrame = UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();
  
   //STEP B: CLIP THE IMAGE
   CGImageRef _regionImage = CGImageCreateWithImageInRect([_fullFrame CGImage], _frameIWant);
   UIImage *_finalImage = [UIImage imageWithCGImage:_regionImage];
   CGImageRelease(_regionImage);
  </code></pre>
  
  <p>'view' is the <code>UIView</code> which I'm clipping and <code>_finalImage</code> is the <code>UIImage</code> I want.</p>
  
  <p>The code works without problem, however is kind of slow. I believe that some performance could be gained by taking just the portion of the screen directly in Step A.</p>
  
  <p>I'm looking for something like <code>renderInContext: withRect:</code> or <code>UIGraphicsGetImageFromCurrentImageContextWithRect()</code> hehe.</p>
  
  <p>Still haven't found anything yet :(, please help me if you know of some alternative.</p>