title: Zooming UIImage/CGImage
body: <p>I am implementing a zooming feature in a camera app using <code>AVFoundation</code>. I am scaling my preview view like this:</p>
  
  <pre><code>[videoPreviewView setTransform:CGAffineTransformMakeScale(cameraZoom, cameraZoom)];
  </code></pre>
  
  <p>Now, after I take a picture, I would like to zoom/crop the picture with the <code>cameraZoom</code> value before I save it to the camera roll. How best should I do this?</p>
  
  <p>Edit: Using Justin's answer:</p>
  
  <pre><code>CGRect imageRect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
  
  CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], imageRect);
  
  CGContextRef bitmapContext = CGBitmapContextCreate(NULL, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef), CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), CGImageGetColorSpace(imageRef), CGImageGetBitmapInfo(imageRef));
  
  CGContextScaleCTM(bitmapContext, scale, scale);
  CGContextDrawImage(bitmapContext, imageRect, imageRef);
  
  CGImageRef zoomedCGImage = CGBitmapContextCreateImage(bitmapContext);
  
  UIImage* zoomedImage = [[UIImage alloc] initWithCGImage:imageRef];
  </code></pre>
  
  <p>It is zooming the image, but it is not taking the center of it, but rather seems to be taking the top right area. (I'm not positive).</p>
  
  <p>The other problem, (I should have been clearer in the OP), is that the image remains the same resolution, but I would rather just crop it down.</p>