Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JimBobBennett

macrumors member
Original poster
May 4, 2009
65
0
I have a UIScrollView, containing a UIImage view, which contains an image from the camera. Once the user has finished scrolling/zooming etc, I want to save just the visible portion of the image.
Sounds simple really. But can I do it? Nope.

I've tried all combinations of multiplying content offsets and scroll view bounds by the scaling factor and who knows what else into a CGRect that I use to extract theimage using CGImageCreateWithImageInRect, but I never get the right image.

Sample code:
CGRect imageFrame = CGRectMake(scrollView.contentOffset.x,
scrollView.contentOffset.y,
scrollView.bounds.size.width * scrollViewZoom,
scrollView.bounds.size.height * scrollViewZoom);

CGImageRef ref = CGImageCreateWithImageInRect([imageView.image CGImage], imageFrame);

// draw this image onto another
myImage = [UIImage imageWithCGImage:ref];


Help! Does anyone have any working example code, or at least a nudge in the right direction to help a newbie developer on his way.

Many thanks in advance!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.