Skip to content

Instantly share code, notes, and snippets.

@Rich86man
Created October 4, 2013 20:13
Show Gist options
  • Save Rich86man/6832040 to your computer and use it in GitHub Desktop.
Save Rich86man/6832040 to your computer and use it in GitHub Desktop.
- (UIImage *)createCroppedImageFromImage:(UIImage *)image {
float scale = 1.0f/self.scrollView.zoomScale;
CGRect visibleRect;
visibleRect.origin.x = self.scrollView.contentOffset.x * scale;
visibleRect.origin.y = self.scrollView.contentOffset.y * scale;
visibleRect.size.width = self.scrollView.bounds.size.width * scale;
visibleRect.size.height = self.scrollView.bounds.size.height * scale;
CGImageRef cr = CGImageCreateWithImageInRect([image CGImage], visibleRect);
UIImage* cropped = [[UIImage alloc] initWithCGImage:cr];
CGImageRelease(cr);
return cropped;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment