title: How to create a UIImage from the current graphics context?
body: <p>I'd like to create a UIImage object from the current graphics context.  More specifically, my use case is a view that the user can draw lines on.  They may draw incrementally.  After they are done, I'd like to create a UIImage to represent their drawing.</p>
  
  <p>Here is what drawRect: looks like for me now:</p>
  
  <pre><code>- (void)drawRect:(CGRect)rect
  {
  CGContextRef c = UIGraphicsGetCurrentContext();
  
  CGContextSaveGState(c);
  CGContextSetStrokeColorWithColor(c, [UIColor blackColor].CGColor);
  CGContextSetLineWidth(c,1.5f);
  
  for(CFIndex i = 0; i &lt; CFArrayGetCount(_pathArray); i++)
  {
      CGPathRef path = CFArrayGetValueAtIndex(_pathArray, i);
      CGContextAddPath(c, path);
  }
  
  CGContextStrokePath(c);
  
  CGContextRestoreGState(c);
  }
  </code></pre>
  
  <p>... where _pathArray is of type CFArrayRef, and is populated every time touchesEnded: is invoked.  Also note that drawRect: may be invoked several times, as the user draws.</p>
  
  <p>When the user is done, I'd like to create a UIImage object that represents the graphics context.  Any suggestions on how to do this?</p>