Thanks to everyone. I figured out a solution. Here is the code I used to get the visible part of the image. (Keep in mind that the image was not fully visible when zoomed in or panned due to the fact that it was shooting the entire screen)
- (UIImage *)cropVisiblePortionOfImageView:(UIImageView *)imageView { CGFloat zoomScaleX=imageView.frame.size.width/initialWidth; CGFloat zoomScaleY=imageView.frame.size.height/initialHeight; CGSize zoomedSize=CGSizeMake(initialWidth*zoomScaleX,initialHeight*zoomScaleY); UIGraphicsBeginImageContext(zoomedSize); [imageView.image drawInRect:CGRectMake(0, 0, zoomedSize.width, zoomedSize.height)]; UIImage *zoomedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIGraphicsBeginImageContext(CGSizeMake(initialWidth, initialHeight)); [zoomedImage drawAtPoint:CGPointMake(imageView.frame.origin.x, imageView.frame.origin.y)]; UIImage *cropedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return cropedImage; }
Walid Hossain Jun 21 '12 at 11:18 2012-06-21 11:18
source share