Skip to content

Instantly share code, notes, and snippets.

@sag333ar
Last active December 28, 2015 09:59
Show Gist options
  • Save sag333ar/7482896 to your computer and use it in GitHub Desktop.
Save sag333ar/7482896 to your computer and use it in GitHub Desktop.
Take screen-shot of current-application-window.
// a function to take screen-shot of application's screen
- (UIImage*)takeScreenshot
{
// get the key-window references
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
// manipulate boundries of key-window
CGRect rect = [keyWindow bounds];
// create context using size
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
// get the context reference
CGContextRef context = UIGraphicsGetCurrentContext();
// render in context
[keyWindow.layer renderInContext:context];
// get the rendered image
UIImage *capturedScreen = UIGraphicsGetImageFromCurrentImageContext();
// complete context
UIGraphicsEndImageContext();
// return image
return takeScreenshot;
}
// -------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment