How can you capture a subset of a screenshot in iOS using Objective-C?

Go To StackoverFlow.com

0

How do you capture only a sub-set of the entire screen using Objective-C on an iOS device?

I found the following code:

UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow];
UIGraphicsBeginImageContext(screenWindow.frame.size);
[screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()]
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();

Which works great but I only want to create an image from a piece of the entire window. How would I go about doing that?

2012-04-03 23:02
by thiesdiggity
possible duplicate of Crop Screen shot ProgramaticallyMichael Dautermann 2012-04-03 23:06
I think you just specify a different size in UIGraphicsBeginImageContext. Then you can do translates to position that frame over the desired part of the view - Hot Licks 2012-04-03 23:08


-1

replace

UIGraphicsBeginImageContext(screenWindow.frame.size);

with

UIGraphicsBeginImageContext(CGSizeMake(width, height));

2012-04-03 23:31
by Greg
is that assuming the x and y are at (0,0)? What if I wanted to take a screen-shot of the center if the image say (50,50) - thiesdiggity 2012-04-03 23:47
@thiesdiggity -- That's where you do the translate thingie, if I understand correctly. But see http://developer.apple.com/library/ios/documentation/uikit/reference/UIKitFunctionReference/UIKitFunctionReference.pd - Hot Licks 2012-04-04 00:24
please remember to accept answers if they answered your question - Greg 2012-04-10 02:14